From 9cad6fc05020e7503e55c2bd7d009e91baf25660 Mon Sep 17 00:00:00 2001 From: mawalu Date: Sat, 14 Aug 2021 13:15:07 +0200 Subject: [PATCH] Start working on launcher mode --- lib/args.nim | 16 ++++++++++------ main.nim | 3 ++- scripts/applications.sh | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100755 scripts/applications.sh diff --git a/lib/args.nim b/lib/args.nim index 5ea896e..26b122c 100644 --- a/lib/args.nim +++ b/lib/args.nim @@ -4,11 +4,11 @@ import os type Args* = object name*: Option[string] - cmd*: Option[string] + cmd*: Option[seq[string]] profile*: Option[string] -proc getCmd*(args: Args): string = - return args.cmd.get(getEnv("SHELL", "/bin/bash")) +proc getCmd*(args: Args): seq[string] = + return args.cmd.get(@[getEnv("SHELL", "/bin/bash")]) proc getProfile*(args: Args): string = if args.profile.isSome: @@ -18,8 +18,8 @@ proc getProfile*(args: Args): string = proc parseOpt(args: var Args, key: string, value: string): bool = case key - of "command", "c": - args.cmd = some(value) + of "name", "n": + args.name = some(value) of "profile", "p": args.profile = some(value) else: @@ -30,6 +30,7 @@ proc parseOpt(args: var Args, key: string, value: string): bool = proc parseArgs*(): Option[Args] = var p = initOptParser() var args = Args() + var command = newSeq[string]() while true: p.next() @@ -40,6 +41,9 @@ proc parseArgs*(): Option[Args] = echo "Invalid argument ", p.val return of cmdArgument: - args.name = some(p.key.string) + command.add(p.key.string) + + if command.len > 0: + args.cmd = some(command) return some(args) \ No newline at end of file diff --git a/main.nim b/main.nim index 8672157..2bd05ca 100644 --- a/main.nim +++ b/main.nim @@ -5,9 +5,10 @@ import random proc main(): int = let args = parseArgs() + echo args if args.isNone: - echo "Usage: bwshell --command=cmd --profile=profile " + echo "Usage: bwshell --name=sandbox_name --profile=profile " return 1 else: randomize() diff --git a/scripts/applications.sh b/scripts/applications.sh new file mode 100755 index 0000000..a0d0507 --- /dev/null +++ b/scripts/applications.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +check_dir() { + local dir=$1 + local file + + for application in "$dir/"*; do + file="$(basename "$application")" + + sed "s/Exec=/Exec=bwrap --name='$file' --profile=gui /gi" "$application" > "$target/$file" + done +} + +dirs=("/usr/share/applications" "$HOME/.local/share/applications") +target="$1" + +for dir in "${dirs[@]}"; do + check_dir "$dir" +done \ No newline at end of file