From 500c5f7c72b7a124305366897041e9f65ab6d25b Mon Sep 17 00:00:00 2001 From: John Mertz Date: Fri, 23 Sep 2022 18:07:06 -0400 Subject: [PATCH] More robust gammastep applet --- waybar/waybar-gammastep.sh | 55 +++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/waybar/waybar-gammastep.sh b/waybar/waybar-gammastep.sh index 5d0c16b..1b0a7e5 100755 --- a/waybar/waybar-gammastep.sh +++ b/waybar/waybar-gammastep.sh @@ -1,18 +1,59 @@ #!/bin/bash -RUNNING=$(pgrep gammastep) +PID=$(pgrep gammastep) +RUNNING=`cat $HOME/.spool/gammastep.status` -if [[ $1 == 'toggle' ]]; then - echo "toggling" - if [ "$RUNNING" ]; then - kill -9 $RUNNING 2&>1 /dev/null +ACTION=$1 +if [[ "$1" == '' ]]; then + ACTION='bar' +fi +echo "$ACTION" >&2 + +if [[ $ACTION == 'bar' ]]; then + : +elif [[ $ACTION == 'toggle' ]]; then + if [ "$PID" ]; then + kill -SIGUSR1 $PID + else + echo 'Gammastep is not running' + fi +elif [[ $ACTION == 'start' ]]; then + if [ "$PID" ]; then + echo 'Gammastep is already running' else $HOME/scripts/sway/gammastep.pl fi - RUNNING=$(pgrep gammastep) +elif [[ $ACTION == 'stop' ]]; then + if [ "$PID" ]; then + kill $PID + else + echo 'Gammastep is not running' + fi +elif [[ $ACTION == 'enable' ]]; then + if [ $PID ]; then + if [ $RUNNING ]; then + echo 'Already enabled' + else + kill -SIGUSR1 $PID + fi + else + echo 'Gammastep is not running' + fi +elif [[ $ACTION == 'disable' ]]; then + if [ $PID ]; then + if [ $RUNNING ]; then + kill -SIGUSR1 $PID + else + echo 'Already disabled' + fi + else + echo 'Gammastep in not running' + fi +else + echo "Invalid argument '$ACTION'. Use 'bar', 'toggle', 'start', 'stop', 'enable', 'disable'." fi - +RUNNING=`cat $HOME/.spool/gammastep.status` if [ "$RUNNING" ]; then echo '{"text":"ɣ","icon":"ɣ","tooltip":"Disable Gammastep","class":"enabled"}' else