diff options
Diffstat (limited to 'config/hypr/UserScripts/RofiCalc.sh')
| -rwxr-xr-x | config/hypr/UserScripts/RofiCalc.sh | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/config/hypr/UserScripts/RofiCalc.sh b/config/hypr/UserScripts/RofiCalc.sh index ccb18903..48f150d8 100755 --- a/config/hypr/UserScripts/RofiCalc.sh +++ b/config/hypr/UserScripts/RofiCalc.sh @@ -10,22 +10,47 @@ rofi_theme="${XDG_CONFIG_HOME:-$HOME/.config}/rofi/config-calc.rasi" -# Kill Rofi if already running before execution -if pgrep -x "rofi" >/dev/null; then - pkill rofi +# Dependency checks +for cmd in rofi qalc wl-copy; do + if ! command -v "$cmd" >/dev/null 2>&1; then + if command -v notify-send >/dev/null 2>&1; then + notify-send -u critical "RofiCalc" "Missing required dependency: $cmd" + else + echo "Error: Missing required dependency: $cmd" >&2 + fi + exit 1 + fi +done + +CALC_LOCKFILE="/tmp/roficalc-${UID:-0}.pid" +if [[ -f "$CALC_LOCKFILE" ]]; then + oldpid="$(cat "$CALC_LOCKFILE" 2>/dev/null || true)" + if [[ -n "$oldpid" ]] && kill -0 "$oldpid" 2>/dev/null; then + kill "$oldpid" 2>/dev/null || true + fi + rm -f "$CALC_LOCKFILE" 2>/dev/null || true fi +printf '%d' "$$" > "$CALC_LOCKFILE" 2>/dev/null || true +trap 'rm -f "$CALC_LOCKFILE" 2>/dev/null' EXIT INT TERM # main function +calc_result="" +result="" while true; do + mesg_args=() + if [[ -n "$result" || -n "$calc_result" ]]; then + mesg_args=(-mesg "$result = $calc_result") + fi + result=$( rofi -i -dmenu \ - -config $rofi_theme \ - -mesg "$result = $calc_result" + -config "$rofi_theme" \ + "${mesg_args[@]}" ) if [ $? -ne 0 ]; then - exit + exit 0 fi if [ -n "$result" ]; then |
