1
0
mirror of https://github.com/frebib/dotfiles.git synced 2024-06-14 12:57:23 +00:00

scripts/systemd-run-i3: fix overriding unit name

systemd-run uses the last passed argument for each flag, so specify the
default first, and the override afterwards, if set
This commit is contained in:
Joe Groocock 2020-04-02 11:19:17 +01:00
parent 928ef584e6
commit 7f79cca7bc
Signed by: frebib
GPG Key ID: E0B16BEACFBB6A86

View File

@ -1,9 +1,11 @@
#!/bin/bash -e #!/bin/bash -e
rand=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 16)
args=() args=()
while getopts "u:s:e:d:cnw" opt while getopts "u:s:e:d:cnw" opt
do case "$opt" in do case "$opt" in
u) args+=("--unit=$OPTARG");; u) args+=("--unit=$OPTARG-$rand");;
s) args+=("--slice=$OPTARG");; s) args+=("--slice=$OPTARG");;
e) args+=("--setenv=$OPTARG");; e) args+=("--setenv=$OPTARG");;
d) args+=("--working-directory=$OPTARG");; d) args+=("--working-directory=$OPTARG");;
@ -15,6 +17,4 @@ do case "$opt" in
done done
shift $((OPTIND-1)) shift $((OPTIND-1))
rand=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 16) exec systemd-run --user --collect --unit="$1-$rand" ${args[@]} -- "$@"
exec systemd-run --user --collect ${args[@]} --unit="$1-$rand" -- "$@"