From 9a3e36fcb10dc9e2144302f118d7305bc5dee8c4 Mon Sep 17 00:00:00 2001 From: mawalu Date: Sun, 29 Aug 2021 19:40:24 +0200 Subject: [PATCH] Update argparser to work with launcher mode --- lib/args.nim | 40 ++++++++++++++++------------------------ scripts/applications.sh | 6 ++++-- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/args.nim b/lib/args.nim index 26b122c..0b9c7b2 100644 --- a/lib/args.nim +++ b/lib/args.nim @@ -1,4 +1,3 @@ -import parseopt import options import os @@ -16,32 +15,25 @@ proc getProfile*(args: Args): string = return "default" -proc parseOpt(args: var Args, key: string, value: string): bool = - case key - of "name", "n": - args.name = some(value) - of "profile", "p": - args.profile = some(value) - else: - return false - - return true - proc parseArgs*(): Option[Args] = - var p = initOptParser() var args = Args() - var command = newSeq[string]() - while true: - p.next() - case p.kind - of cmdEnd: break - of cmdShortOption, cmdLongOption: - if p.val == "" or args.parseOpt(p.key, p.val) == false: - echo "Invalid argument ", p.val - return - of cmdArgument: - command.add(p.key.string) + var command = newSeq[string]() + var i = 1 + + while i <= paramCount(): + var arg = paramStr(i) + + if arg == "--name": + args.name = some(paramStr(i + 1)) + i += 2 + elif arg == "--profile": + args.profile = some(paramStr(i + 1)) + i += 2 + else: + echo arg + command.add(arg) + i += 1 if command.len > 0: args.cmd = some(command) diff --git a/scripts/applications.sh b/scripts/applications.sh index a0d0507..4990660 100755 --- a/scripts/applications.sh +++ b/scripts/applications.sh @@ -12,13 +12,15 @@ check_dir() { for application in "$dir/"*; do file="$(basename "$application")" - sed "s/Exec=/Exec=bwrap --name='$file' --profile=gui /gi" "$application" > "$target/$file" + sed "s/Exec=/Exec=bwshell --name '$file' --profile gui /gi" "$application" > "$target/$file" done } dirs=("/usr/share/applications" "$HOME/.local/share/applications") target="$1" +mkdir -p "$target" + for dir in "${dirs[@]}"; do check_dir "$dir" -done \ No newline at end of file +done