From 9a16998e649d51e1f323b1f30036c34a9a934a8c Mon Sep 17 00:00:00 2001 From: Miles Alan Date: Wed, 27 May 2020 20:16:11 -0500 Subject: [PATCH] Rework timer script and timezone script to use $# checking/recursive call trick --- scripts/appscripts/sxmo_timer.sh | 66 ++++++++++++++++++++-------- scripts/appscripts/sxmo_timermenu.sh | 21 --------- scripts/core/sxmo_timezonechange.sh | 26 ++++++++--- 3 files changed, 66 insertions(+), 47 deletions(-) delete mode 100755 scripts/appscripts/sxmo_timermenu.sh diff --git a/scripts/appscripts/sxmo_timer.sh b/scripts/appscripts/sxmo_timer.sh index a7efd3d..6e5546b 100755 --- a/scripts/appscripts/sxmo_timer.sh +++ b/scripts/appscripts/sxmo_timer.sh @@ -1,23 +1,51 @@ #!/usr/bin/env sh +timerrun() { + TIME=$( + echo "$@" | + sed 's#h#*60m#g'| + sed 's#m#*60s#g'| + sed 's#s#*1#g'| + sed 's# #+#g' | + bc + ) -TIME=$( - echo "$@" | - sed 's#h#*60m#g'| - sed 's#m#*60s#g'| - sed 's#s#*1#g'| - sed 's# #+#g' | - bc -) + date1=$((`date +%s` + $TIME)); + while [ "$date1" -ge `date +%s` ]; do + echo -ne "$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S) \r"; + sleep 0.1 + done + echo "Done with $@" -date1=$((`date +%s` + $TIME)); -while [ "$date1" -ge `date +%s` ]; do - echo -ne "$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S) \r"; - sleep 0.1 -done -echo "Done with $@" + while :; + do notify-send "Done with $@"; + sxmo_vibratepine 1000 + sleep 0.5 + done +} -while :; - do notify-send "Done with $@"; - sxmo_vibratepine 1000 - sleep 0.5 -done +menu() { + pidof svkbd-sxmo || svkbd-sxmo & + TIMEINPUT="$( + echo -e " + 1h + 10m + 9m + 8m + 7m + 6m + 5m + 4m + 3m + 2m + 1m + 30s + Close Menu + " | awk 'NF' | awk '{$1=$1};1' | dmenu -p Timer -c -fn "Terminus-30" -l 20 + )" + pkill svkbd-sxmo + [[ "Close Menu" == "$TIMEINPUT" ]] && exit 0 + + st -f Monospace-50 -e $0 timerrun $TIMEINPUT +} + +[ $# -gt 0 ] && $@ || menu \ No newline at end of file diff --git a/scripts/appscripts/sxmo_timermenu.sh b/scripts/appscripts/sxmo_timermenu.sh deleted file mode 100755 index 8aae763..0000000 --- a/scripts/appscripts/sxmo_timermenu.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env sh -pidof svkbd-sxmo || svkbd-sxmo & -TIMEINPUT="$( -echo "1h -10m -9m -8m -7m -6m -5m -4m -3m -2m -1m -30s -Close Menu" | dmenu -p Timer -c -fn "Terminus-30" -l 20 -)" -pkill svkbd-sxmo -[[ "Close Menu" == "$TIMEINPUT" ]] && exit 0 - -st -f Monospace-50 -e sxmo_timer.sh $TIMEINPUT diff --git a/scripts/core/sxmo_timezonechange.sh b/scripts/core/sxmo_timezonechange.sh index 4b1dc67..cc1fee3 100755 --- a/scripts/core/sxmo_timezonechange.sh +++ b/scripts/core/sxmo_timezonechange.sh @@ -1,9 +1,21 @@ #!/usr/bin/env sh -T="$( - find /usr/share/zoneinfo -type f | - sed 's#^/usr/share/zoneinfo/##g' | - sort | - sxmo_dmenu_with_kb.sh -p Timezone -c -l 10 -fn Terminus-20 -i -)" -st -e sh -c 'sudo setup-timezone -z '$T' && echo 1 > /tmp/sxmo_bar && echo Timezone changed ok && read' +change() { + echo "Changing timezone to $1" + sudo setup-timezone -z "$1" + echo 1 > /tmp/sxmo_bar + echo Timezone changed ok + read +} + +menu() { + T="$( + find /usr/share/zoneinfo -type f | + sed 's#^/usr/share/zoneinfo/##g' | + sort | + sxmo_dmenu_with_kb.sh -p Timezone -c -l 10 -fn Terminus-20 -i + )" + st -e "$0" change "$T" +} + +[ $# -gt 0 ] && $@ || menu \ No newline at end of file