Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
9a3e36fcb1
|
|||
|
9cad6fc050
|
|||
|
354ba05faa
|
48
lib/args.nim
48
lib/args.nim
@@ -1,14 +1,13 @@
|
|||||||
import parseopt
|
|
||||||
import options
|
import options
|
||||||
import os
|
import os
|
||||||
|
|
||||||
type Args* = object
|
type Args* = object
|
||||||
name*: Option[string]
|
name*: Option[string]
|
||||||
cmd*: Option[string]
|
cmd*: Option[seq[string]]
|
||||||
profile*: Option[string]
|
profile*: Option[string]
|
||||||
|
|
||||||
proc getCmd*(args: Args): string =
|
proc getCmd*(args: Args): seq[string] =
|
||||||
return args.cmd.get(getEnv("SHELL", "/bin/bash"))
|
return args.cmd.get(@[getEnv("SHELL", "/bin/bash")])
|
||||||
|
|
||||||
proc getProfile*(args: Args): string =
|
proc getProfile*(args: Args): string =
|
||||||
if args.profile.isSome:
|
if args.profile.isSome:
|
||||||
@@ -16,30 +15,27 @@ proc getProfile*(args: Args): string =
|
|||||||
|
|
||||||
return "default"
|
return "default"
|
||||||
|
|
||||||
proc parseOpt(args: var Args, key: string, value: string): bool =
|
|
||||||
case key
|
|
||||||
of "command", "c":
|
|
||||||
args.cmd = some(value)
|
|
||||||
of "profile", "p":
|
|
||||||
args.profile = some(value)
|
|
||||||
else:
|
|
||||||
return false
|
|
||||||
|
|
||||||
return true
|
|
||||||
|
|
||||||
proc parseArgs*(): Option[Args] =
|
proc parseArgs*(): Option[Args] =
|
||||||
var p = initOptParser()
|
|
||||||
var args = Args()
|
var args = Args()
|
||||||
|
|
||||||
while true:
|
var command = newSeq[string]()
|
||||||
p.next()
|
var i = 1
|
||||||
case p.kind
|
|
||||||
of cmdEnd: break
|
while i <= paramCount():
|
||||||
of cmdShortOption, cmdLongOption:
|
var arg = paramStr(i)
|
||||||
if p.val == "" or args.parseOpt(p.key, p.val) == false:
|
|
||||||
echo "Invalid argument ", p.val
|
if arg == "--name":
|
||||||
return
|
args.name = some(paramStr(i + 1))
|
||||||
of cmdArgument:
|
i += 2
|
||||||
args.name = some(p.key.string)
|
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)
|
||||||
|
|
||||||
return some(args)
|
return some(args)
|
||||||
@@ -10,10 +10,10 @@ type DbusProxy* = object
|
|||||||
socket*: string
|
socket*: string
|
||||||
args: seq[string]
|
args: seq[string]
|
||||||
|
|
||||||
proc exec*(proxy: var DbusProxy) =
|
proc exec*(proxy: DbusProxy): Process =
|
||||||
# todo: start dbus proxy in bwrap
|
# todo: start dbus proxy in bwrap
|
||||||
# todo: pass arguments as fd
|
# todo: pass arguments as fd
|
||||||
proxy.process = startProcess("xdg-dbus-proxy", args = proxy.args,
|
startProcess("xdg-dbus-proxy", args = proxy.args,
|
||||||
options = {poEchoCmd, poParentStreams, poUsePath})
|
options = {poEchoCmd, poParentStreams, poUsePath})
|
||||||
|
|
||||||
proc startDBusProxy*(config: Config, hostname: string): DbusProxy =
|
proc startDBusProxy*(config: Config, hostname: string): DbusProxy =
|
||||||
@@ -49,6 +49,6 @@ proc startDBusProxy*(config: Config, hostname: string): DbusProxy =
|
|||||||
|
|
||||||
proxy.args.add("--filter")
|
proxy.args.add("--filter")
|
||||||
proxy.args.add("--log")
|
proxy.args.add("--log")
|
||||||
proxy.exec()
|
proxy.process = proxy.exec()
|
||||||
|
|
||||||
proxy
|
proxy
|
||||||
3
main.nim
3
main.nim
@@ -5,9 +5,10 @@ import random
|
|||||||
|
|
||||||
proc main(): int =
|
proc main(): int =
|
||||||
let args = parseArgs()
|
let args = parseArgs()
|
||||||
|
echo args
|
||||||
|
|
||||||
if args.isNone:
|
if args.isNone:
|
||||||
echo "Usage: bwshell --command=cmd --profile=profile <sandbox_name>"
|
echo "Usage: bwshell --name=sandbox_name --profile=profile <sandbox_cmd>"
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
randomize()
|
randomize()
|
||||||
|
|||||||
26
scripts/applications.sh
Executable file
26
scripts/applications.sh
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ $# -ne 1 ]; then
|
||||||
|
echo "Usage: $0 <target_dir>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
check_dir() {
|
||||||
|
local dir=$1
|
||||||
|
local file
|
||||||
|
|
||||||
|
for application in "$dir/"*; do
|
||||||
|
file="$(basename "$application")"
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user