Allow specifying a specific mode as an argument

This commit is contained in:
John Mertz 2023-08-13 22:27:34 -06:00
parent 4edd9a297d
commit 7af9d67b29
Signed by: jpm
GPG Key ID: E9C5EA2D867501AB
1 changed files with 27 additions and 22 deletions

View File

@ -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