2024-03-26 20:03:07 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2025-06-18 09:47:16 -07:00
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
2025-06-18 09:54:29 -07:00
|
|
|
export ROOT="$ROOT"
|
2025-06-18 09:47:16 -07:00
|
|
|
button="$1"
|
2025-06-13 16:09:14 -07:00
|
|
|
|
|
|
|
debug(){
|
2025-06-18 09:54:29 -07:00
|
|
|
debug="$ROOT"/debug
|
2025-06-13 16:25:23 -07:00
|
|
|
# todo:
|
|
|
|
# this keeps the log file at 30 lines but breaks the pipe when doing "tail -F debug"
|
2025-06-18 09:54:29 -07:00
|
|
|
tail -n 30 "$debug" > debug.tmp && mv debug.tmp "$debug"
|
2025-06-18 09:47:16 -07:00
|
|
|
echo "$1"
|
2025-06-18 09:54:29 -07:00
|
|
|
echo "$1">>"$debug"
|
2025-06-13 16:09:14 -07:00
|
|
|
}
|
2025-06-13 16:25:23 -07:00
|
|
|
|
2025-06-18 09:54:29 -07:00
|
|
|
active=$(bash "$ROOT"/get_active_window.sh)
|
2025-06-13 16:09:14 -07:00
|
|
|
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"
|
2024-03-26 20:03:07 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
### find and run $1
|
2025-06-18 09:47:16 -07:00
|
|
|
if [[ $(type -t "$active") == function ]]; then
|
2025-06-13 16:09:14 -07:00
|
|
|
debug "found $active methods"
|
2025-06-18 09:47:16 -07:00
|
|
|
"$active"
|
2025-06-13 16:09:14 -07:00
|
|
|
else
|
|
|
|
debug "no $button method found in $active"
|
|
|
|
fi
|
|
|
|
|
2025-06-18 09:47:16 -07:00
|
|
|
if [[ $(type -t "$button") == function ]]; then
|
2025-06-13 16:09:14 -07:00
|
|
|
debug "found $button"
|
2025-06-18 09:47:16 -07:00
|
|
|
"$1"
|
2024-03-26 20:03:07 -07:00
|
|
|
else
|
2025-06-13 16:09:14 -07:00
|
|
|
debug "program specific method not found calling all $button"
|
2025-06-18 09:47:16 -07:00
|
|
|
all "$1"
|
2024-03-26 20:03:07 -07:00
|
|
|
fi
|
|
|
|
|