diff options
-rw-r--r-- | X11/openbox/rc.xml | 25 | ||||
-rwxr-xr-x | bin/unix/timer.sh | 17 |
2 files changed, 27 insertions, 15 deletions
diff --git a/X11/openbox/rc.xml b/X11/openbox/rc.xml index aa58b85..96e271e 100644 --- a/X11/openbox/rc.xml +++ b/X11/openbox/rc.xml | |||
@@ -499,14 +499,23 @@ | |||
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 TIMER --hold | 502 | sh -c ' |
503 | -o "window.dimensions.columns=8" | 503 | xdotool search --name "TIMER" windowactivate || \ |
504 | -o "window.dimensions.lines=1" | 504 | alacritty --title TIMER --hold \ |
505 | -o "window.position.x=-0" | 505 | -o "window.dimensions.columns=8" \ |
506 | -o "window.position.y=0" | 506 | -o "window.dimensions.lines=1" \ |
507 | -o "window.opacity=0.6" | 507 | -o "window.position.x=-0" \ |
508 | -o "font.size=40" | 508 | -o "window.position.y=0" \ |
509 | -e ~/helper/bin/unix/timer.sh SIGINT | 509 | -o "window.opacity=0.6" \ |
510 | -o "font.size=40" \ | ||
511 | -e ~/helper/bin/unix/timer.sh SIGINT | ||
512 | ' | ||
513 | </command> | ||
514 | </action> | ||
515 | </keybind> | ||
516 | <keybind key="W-S-t"> | ||
517 | <action name="Execute"> | ||
518 | <command> | ||
510 | </command> | 519 | </command> |
511 | </action> | 520 | </action> |
512 | </keybind> | 521 | </keybind> |
diff --git a/bin/unix/timer.sh b/bin/unix/timer.sh index ea15985..ca807e8 100755 --- a/bin/unix/timer.sh +++ b/bin/unix/timer.sh | |||
@@ -6,6 +6,7 @@ SIGNAL=${1:-SIGTERM} | |||
6 | # If SIGNAL is received, switch to next display | 6 | # If SIGNAL is received, switch to next display |
7 | trap 'next_display' "$SIGNAL" | 7 | trap 'next_display' "$SIGNAL" |
8 | trap 'toggle_timer' SIGTSTP | 8 | trap 'toggle_timer' SIGTSTP |
9 | |||
9 | # Do not print "^C" when SIGINT caught | 10 | # Do not print "^C" when SIGINT caught |
10 | stty -ctlecho | 11 | stty -ctlecho |
11 | 12 | ||
@@ -26,17 +27,19 @@ toggle_timer() { | |||
26 | 27 | ||
27 | # Wait user input | 28 | # Wait user input |
28 | read -p '? ' -r input | 29 | read -p '? ' -r input |
30 | # Disable input on terminal | ||
31 | stty -echo | ||
29 | 32 | ||
30 | # Modify input to fit the format that `date` can read | 33 | # Modify input to fit the format that `date` can read |
31 | # s -> sec | 34 | hour=$(grep -o '[0-9.]\+h' <<<"$input" | tr -d h) |
32 | # m -> min | 35 | min=$(grep -o '[0-9.]\+m' <<<"$input" | tr -d m) |
33 | # h -> hour | 36 | sec=$(grep -o '[0-9.]\+s' <<<"$input" | tr -d s) |
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 | 37 | ||
38 | # seconds user set | 38 | # seconds user set |
39 | SET=$(( $(date +%s -d "$input") - $(date +%s) )) | 39 | SET=$( echo "${hour:-0}*3600 + ${min:-0}*60 + ${sec:-0}" | bc ) |
40 | # Make sure the value is integer, prevent fail in shell comparison | ||
41 | SET=${SET%%.*} | ||
42 | |||
40 | # seconds pass | 43 | # seconds pass |
41 | count=0 | 44 | count=0 |
42 | 45 | ||