PJ/buttons.sh
2025-06-18 09:47:16 -07:00

46 lines
953 B
Bash
Executable file

#!/bin/bash
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export ROOT=ROOT
button="$1"
debug(){
debug=$ROOT/debug
# todo:
# this keeps the log file at 30 lines but breaks the pipe when doing "tail -F debug"
tail -n 30 $debug > debug.tmp && mv debug.tmp $debug
echo "$1"
echo "$1">>$debug
}
active=$(bash $ROOT/get_active_window.sh)
debug ""
debug "$(date +%s)"
debug "active: $active"
debug "button: $button"
. $ROOT/find_or_open.sh
. $ROOT/apps/default_commands.sh
if [ -f "$ROOT/apps/${active%%_*}.sh" ]; then
. "$ROOT/apps/${active%%_*}.sh"
debug "$active sourced"
else
debug "no $active source found"
fi
### find and run $1
if [[ $(type -t "$active") == function ]]; then
debug "found $active methods"
"$active"
else
debug "no $button method found in $active"
fi
if [[ $(type -t "$button") == function ]]; then
debug "found $button"
"$1"
else
debug "program specific method not found calling all $button"
all "$1"
fi