diff options
| -rw-r--r-- | X11/openbox/rc.xml | 24 | ||||
| -rwxr-xr-x | bin/unix/countdown.sh | 34 | ||||
| -rwxr-xr-x | bin/unix/stopwatch.sh | 37 | ||||
| -rwxr-xr-x | bin/unix/timer.sh | 62 |
4 files changed, 65 insertions, 92 deletions
diff --git a/X11/openbox/rc.xml b/X11/openbox/rc.xml index b0def68..aa58b85 100644 --- a/X11/openbox/rc.xml +++ b/X11/openbox/rc.xml | |||
| @@ -499,27 +499,17 @@ | |||
| 499 | <keybind key="W-t"> | 499 | <keybind key="W-t"> |
| 500 | <action name="Execute"> | 500 | <action name="Execute"> |
| 501 | <command> | 501 | <command> |
| 502 | alacritty --title STOPWATCH --hold | 502 | alacritty --title TIMER --hold |
| 503 | -o "window.dimensions.columns=8" | 503 | -o "window.dimensions.columns=8" |
| 504 | -o "window.dimensions.lines=1" | 504 | -o "window.dimensions.lines=1" |
| 505 | -o "window.position.x=-0" | 505 | -o "window.position.x=-0" |
| 506 | -o "window.position.y=0" | 506 | -o "window.position.y=0" |
| 507 | -o "window.opacity=0.6" | 507 | -o "window.opacity=0.6" |
| 508 | -o "font.size=40" | 508 | -o "font.size=40" |
| 509 | -e ~/helper/bin/unix/stopwatch.sh | 509 | -e ~/helper/bin/unix/timer.sh SIGINT |
| 510 | </command> | 510 | </command> |
| 511 | </action> | 511 | </action> |
| 512 | </keybind> | 512 | </keybind> |
| 513 | <keybind key="W-S-t"> | ||
| 514 | <action name="ForEach"> | ||
| 515 | <query target="default"> | ||
| 516 | <title type="exact">STOPWATCH</title> | ||
| 517 | </query> | ||
| 518 | <then> | ||
| 519 | <action name="Focus"/> | ||
| 520 | </then> | ||
| 521 | </action> | ||
| 522 | </keybind> | ||
| 523 | <keybind key="W-y"> | 513 | <keybind key="W-y"> |
| 524 | <action name="Execute"> | 514 | <action name="Execute"> |
| 525 | <command> | 515 | <command> |
| @@ -1032,15 +1022,7 @@ | |||
| 1032 | <width>50%</width> | 1022 | <width>50%</width> |
| 1033 | </size> | 1023 | </size> |
| 1034 | </application> | 1024 | </application> |
| 1035 | <application title="STOPWATCH"> | 1025 | <application title="TIMER"> |
| 1036 | <position force="yes"> | ||
| 1037 | <x>-0</x> | ||
| 1038 | <y>-0</y> | ||
| 1039 | </position> | ||
| 1040 | <layer>above</layer> | ||
| 1041 | <skip_taskbar>yes</skip_taskbar> | ||
| 1042 | </application> | ||
| 1043 | <application title="COUNTDOWN"> | ||
| 1044 | <position force="yes"> | 1026 | <position force="yes"> |
| 1045 | <x>-0</x> | 1027 | <x>-0</x> |
| 1046 | <y>-0</y> | 1028 | <y>-0</y> |
diff --git a/bin/unix/countdown.sh b/bin/unix/countdown.sh deleted file mode 100755 index ca6b5d6..0000000 --- a/bin/unix/countdown.sh +++ /dev/null | |||
| @@ -1,34 +0,0 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | ||
| 3 | |||
| 4 | # If user type '^C', then use SIGINT to toggle the display | ||
| 5 | trap '[ "$SHOWGIVEN" = yes ] && SHOWGIVEN= || SHOWGIVEN=yes' SIGINT | ||
| 6 | # Do not print "^C" when SIGINT caught | ||
| 7 | stty -ctlecho | ||
| 8 | |||
| 9 | # Hide the cursor | ||
| 10 | tput civis | ||
| 11 | |||
| 12 | # Wait user input | ||
| 13 | read -p '? ' input | ||
| 14 | |||
| 15 | # Modify input to fit the format that `date` can read | ||
| 16 | # s -> sec | ||
| 17 | # m -> min | ||
| 18 | # h -> hour | ||
| 19 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | ||
| 20 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | ||
| 21 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | ||
| 22 | |||
| 23 | start=$(date +%s -d "$input") | ||
| 24 | while [ "$start" -ge $(date +%s) ]; do | ||
| 25 | ## Is this more than 24h away? | ||
| 26 | time="$(( $start - `date +%s` ))" | ||
| 27 | if [ -z "$SHOWGIVEN" ]; then | ||
| 28 | printf '%s\r' "$(date -u -d @$time +%H:%M:%S)" | ||
| 29 | else | ||
| 30 | printf '%s\r' "$(date -d "00 + $input" +%H:%M:%S)" | ||
| 31 | fi | ||
| 32 | sleep 0.3 | ||
| 33 | done | ||
| 34 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | ||
diff --git a/bin/unix/stopwatch.sh b/bin/unix/stopwatch.sh deleted file mode 100755 index 6b76c26..0000000 --- a/bin/unix/stopwatch.sh +++ /dev/null | |||
| @@ -1,37 +0,0 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | ||
| 3 | |||
| 4 | # If user type '^C', then use SIGINT to toggle the display | ||
| 5 | trap '[ "$SHOWGIVEN" = yes ] && SHOWGIVEN= || SHOWGIVEN=yes' SIGINT | ||
| 6 | # Do not print "^C" when SIGINT caught | ||
| 7 | stty -ctlecho | ||
| 8 | |||
| 9 | # Hide the cursor | ||
| 10 | tput civis | ||
| 11 | |||
| 12 | # Wait user input | ||
| 13 | read -p '? ' input | ||
| 14 | |||
| 15 | # Modify input to fit the format that `date` can read | ||
| 16 | # s -> sec | ||
| 17 | # m -> min | ||
| 18 | # h -> hour | ||
| 19 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | ||
| 20 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | ||
| 21 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | ||
| 22 | |||
| 23 | time=0 | ||
| 24 | start=$(date +%s) | ||
| 25 | given=$(date +%s -d "$input") | ||
| 26 | stop=$(( $given - $start )) | ||
| 27 | while [ $time -ne $stop ]; do | ||
| 28 | time="$(( $(date +%s) - $start ))" | ||
| 29 | if [ -z "$SHOWGIVEN" ]; then | ||
| 30 | printf '%s\r' "$(date -u -d @$time +%H:%M:%S)" | ||
| 31 | else | ||
| 32 | printf '%s\r' "$(date -u -d @$stop +%H:%M:%S)" | ||
| 33 | fi | ||
| 34 | sleep 0.3 | ||
| 35 | done | ||
| 36 | |||
| 37 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | ||
diff --git a/bin/unix/timer.sh b/bin/unix/timer.sh new file mode 100755 index 0000000..ac9c858 --- /dev/null +++ b/bin/unix/timer.sh | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | ||
| 3 | |||
| 4 | SIGNAL=${1:-SIGTERM} | ||
| 5 | |||
| 6 | # If SIGNAL is received, switch to next display | ||
| 7 | trap 'next_display' $SIGNAL | ||
| 8 | #trap 'toggle_timer' SIGTSTP | ||
| 9 | # Do not print "^C" when SIGINT caught | ||
| 10 | stty -ctlecho | ||
| 11 | |||
| 12 | # Hide the cursor | ||
| 13 | tput civis | ||
| 14 | |||
| 15 | display_list=(STOPWATCH COUNTDOWN PERIOD) | ||
| 16 | export DISPLAY=0 | ||
| 17 | |||
| 18 | next_display() { | ||
| 19 | export DISPLAY=$(( ($DISPLAY + 1) %${#display_list[@]} )) | ||
| 20 | } | ||
| 21 | |||
| 22 | export stop= | ||
| 23 | toggle_timer() { | ||
| 24 | [ "$stop" = true ] && export stop= || export stop=true | ||
| 25 | } | ||
| 26 | |||
| 27 | # Wait user input | ||
| 28 | read -p '? ' input | ||
| 29 | |||
| 30 | # Modify input to fit the format that `date` can read | ||
| 31 | # s -> sec | ||
| 32 | # m -> min | ||
| 33 | # h -> hour | ||
| 34 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | ||
| 35 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | ||
| 36 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | ||
| 37 | |||
| 38 | start=$(date +%s) # unix epoch of start | ||
| 39 | given=$(date +%s -d "$input") # unix epoch of end | ||
| 40 | period=$(( $given - $start )) # seconds for timer | ||
| 41 | |||
| 42 | time=0 | ||
| 43 | while [ $time -ne $period ]; do | ||
| 44 | [ "$stop" = true ] && sleep 0.3 && continue | ||
| 45 | |||
| 46 | time="$(( $(date +%s) - $start ))" | ||
| 47 | case ${display_list[$DISPLAY]} in | ||
| 48 | STOPWATCH) | ||
| 49 | printf '%s\r' "$(date -u -d @$time +%H:%M:%S)" | ||
| 50 | ;; | ||
| 51 | COUNTDOWN) | ||
| 52 | printf '%s\r' "$(date -u -d @$((period - $time)) +%H:%M:%S)" | ||
| 53 | ;; | ||
| 54 | PERIOD) | ||
| 55 | printf '%s\r' "$(date -u -d @$period +%H:%M:%S)" | ||
| 56 | ;; | ||
| 57 | esac | ||
| 58 | |||
| 59 | sleep 0.3 | ||
| 60 | done | ||
| 61 | |||
| 62 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | ||