✨ allow multiple run commands (fix #1)
This commit is contained in:
parent
60cc1357db
commit
28accc88b9
44
workplace
44
workplace
@ -75,15 +75,30 @@ workplace_set(){
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
## RUN SET COMMANDS ##
|
## RUN COMMANDS ##
|
||||||
local -n workplace_section="ini__$workplace_name"
|
local -n workplace_section="ini__${workplace_name}"
|
||||||
for k in "${!workplace_section[@]}"; do
|
local -n workplace_section_key_list="ini__${workplace_name}__key_list"
|
||||||
|
for k in ${workplace_section_key_list[*]}; do
|
||||||
# `set` command
|
# `set` command
|
||||||
if [[ "$k" =~ ^set\. ]]; then
|
if [[ "$k" =~ ^set\. ]]; then
|
||||||
command=$(echo "$k" | grep -oPe '(?<=^set.).*')
|
command=$(echo "$k" | grep -oPe '(?<=^set.).*')
|
||||||
param="${workplace_section[$k]}"
|
param="${workplace_section[$k]}"
|
||||||
workplace_setcommand_run "$command" "$param"
|
workplace_setcommand_run "$command" "$param"
|
||||||
continue; fi
|
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
|
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 ##
|
## ERROR HANDLING ##
|
||||||
*)
|
*)
|
||||||
log_error "Invalid setcommand '$1'"
|
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.
|
# HELPER: Get list of connected usb device ids.
|
||||||
#
|
#
|
||||||
|
@ -6,7 +6,10 @@ set.text-scaling-factor = 1.3700000000000001
|
|||||||
set.powerprofile = power-saver
|
set.powerprofile = power-saver
|
||||||
set.volume = 0
|
set.volume = 0
|
||||||
set.pam.fprintd = true
|
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.powerprofile = balanced
|
||||||
set.volume = 90
|
set.volume = 90
|
||||||
set.pam.fprintd = false
|
set.pam.fprintd = false
|
||||||
set.run = echo dock!
|
|
||||||
|
run.echo = "echo dock!"
|
||||||
|
run.blabla = "for x in {1..10}; do echo $x; done"
|
||||||
|
Loading…
Reference in New Issue
Block a user