allow multiple run commands (fix #1)

This commit is contained in:
DrMaxNix 2024-05-31 22:55:21 +02:00
parent 60cc1357db
commit 28accc88b9
2 changed files with 38 additions and 15 deletions

View File

@ -75,15 +75,30 @@ workplace_set(){
fi
## RUN SET COMMANDS ##
local -n workplace_section="ini__$workplace_name"
for k in "${!workplace_section[@]}"; do
## RUN COMMANDS ##
local -n workplace_section="ini__${workplace_name}"
local -n workplace_section_key_list="ini__${workplace_name}__key_list"
for k in ${workplace_section_key_list[*]}; do
# `set` command
if [[ "$k" =~ ^set\. ]]; then
command=$(echo "$k" | grep -oPe '(?<=^set.).*')
param="${workplace_section[$k]}"
workplace_setcommand_run "$command" "$param"
continue; fi
# `run` command
if [[ "$k" =~ ^run\. ]]; then
param="${workplace_section[$k]}"
workplace_runcommand_run "$param"
continue; fi
# `trigger` command
if [[ "$k" =~ ^trigger\. ]]; then
# ignore
continue; fi
# unknown command type
log_warn "Unknown command type for '$k'"
done
}
@ -266,16 +281,6 @@ workplace_setcommand_run(){
;;
## CUSTOM COMMAND ##
"run")
eval_exit=0
eval "$2" || eval_exit=$?
if [[ "$eval_exit" -gt 0 ]]; then
log_warn "Custom command failed: '$2'"
fi
;;
## ERROR HANDLING ##
*)
log_error "Invalid setcommand '$1'"
@ -286,6 +291,19 @@ workplace_setcommand_run(){
#
# HELPER: Run a `run` command.
#
workplace_runcommand_run(){
bash_exit=0
bash -c "$1" 1>&2 || bash_exit=$?
if [[ "$bash_exit" -gt 0 ]]; then
log_warn "Run command failed: '$1'"
fi
}
#
# HELPER: Get list of connected usb device ids.
#

View File

@ -6,7 +6,10 @@ set.text-scaling-factor = 1.3700000000000001
set.powerprofile = power-saver
set.volume = 0
set.pam.fprintd = true
set.run = echo laptop!
run.echo = "echo laptop!"
run.other-command = "export var=42; echo $var"
run.my-script = "/path/to/script arg1 arg2 arg3"
@ -18,4 +21,6 @@ set.text-scaling-factor = 1.0
set.powerprofile = balanced
set.volume = 90
set.pam.fprintd = false
set.run = echo dock!
run.echo = "echo dock!"
run.blabla = "for x in {1..10}; do echo $x; done"