From 7af9d67b29430939f1ab2bb4292647bcaf8aec01 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Sun, 13 Aug 2023 22:27:34 -0600 Subject: [PATCH] Allow specifying a specific mode as an argument --- waybar/waybar-idle.sh | 49 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/waybar/waybar-idle.sh b/waybar/waybar-idle.sh index f7383a5..98932cc 100755 --- a/waybar/waybar-idle.sh +++ b/waybar/waybar-idle.sh @@ -1,40 +1,45 @@ #!/bin/bash FILE="$HOME/.spool/idle_mode" -if [ -e $FILE ]; then - MODE=$(cat $FILE) +if [[ -z $1 ]] || [[ "$1" == 'rotate' ]] || [[ "$1" == 'bar' ]]; then + if [[ -e $FILE ]]; then + MODE=$(cat $FILE) + else + MODE="fade" + fi else - MODE="fade" - echo -n $MODE >$FILE + MODE="$1" fi if [[ $MODE == "none" ]]; then - NEXT="fade" - ICON="☕" + NEXT="fade" + ICON="☕" elif [[ $MODE == "fade" ]]; then - ICON="🌌" - NEXT="dim" + ICON="🌌" + NEXT="dim" elif [[ $MODE == "dim" ]]; then - ICON="⬛" - NEXT="lock" + ICON="⬛" + NEXT="lock" elif [[ $MODE == "lock" ]]; then - ICON="🔒" - NEXT="sleep" + ICON="🔒" + NEXT="sleep" elif [[ $MODE == "sleep" ]]; then - ICON="💤" - NEXT="hibernate" + ICON="💤" + NEXT="hibernate" elif [[ $MODE == "hibernate" ]]; then - ICON="↯ " - NEXT="none" + ICON="↯ " + NEXT="none" else - echo "Invalid mode: $MODE" + echo "Invalid mode: $MODE" + exit fi -if [ -z $1 ] || [ "$1" == "bar" ]; then - echo '{"text":"'$ICON'","icon":"'$ICON'","tooltip":"Change sleep mode ('$MODE')","class":"'$MODE'"}' +if [[ -z $1 ]] || [[ "$1" == "bar" ]]; then + echo '{"text":"'$ICON'","icon":"'$ICON'","tooltip":"Change sleep mode ('$MODE')","class":"'$MODE'"}' elif [ "$1" == "rotate" ]; then - echo -n $NEXT >$FILE - $0 bar + echo -n $NEXT >$FILE + $0 bar else - echo "Invalid argumuent $1" + echo -n $MODE >$FILE + $0 bar fi