diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-02-22 22:17:04 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-02-22 22:17:04 +0800 |
| commit | e8354fe44d01714d0a1b8a40d1f3d352dd2cb876 (patch) | |
| tree | ba24ca13ec173491325d0ac96deaaeb60fac3090 | |
| parent | a6b213ce349f91cbe688e3749c0cfa8cadb4a8fa (diff) | |
Update
| -rw-r--r-- | X11/openbox/rc.xml | 26 | ||||
| -rwxr-xr-x | bin/unix/countdown.sh | 19 | ||||
| -rwxr-xr-x | bin/unix/stopwatch.sh | 19 |
3 files changed, 61 insertions, 3 deletions
diff --git a/X11/openbox/rc.xml b/X11/openbox/rc.xml index f5797ae..b0def68 100644 --- a/X11/openbox/rc.xml +++ b/X11/openbox/rc.xml | |||
| @@ -504,12 +504,23 @@ | |||
| 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 "font.size=40" | 508 | -o "font.size=40" |
| 508 | -e ~/helper/bin/unix/stopwatch.sh | 509 | -e ~/helper/bin/unix/stopwatch.sh |
| 509 | </command> | 510 | </command> |
| 510 | </action> | 511 | </action> |
| 511 | </keybind> | 512 | </keybind> |
| 512 | <keybind key="W-S-t"> | 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 | <action name="Execute"> | 524 | <action name="Execute"> |
| 514 | <command> | 525 | <command> |
| 515 | alacritty --title COUNTDOWN --hold | 526 | alacritty --title COUNTDOWN --hold |
| @@ -517,11 +528,22 @@ | |||
| 517 | -o "window.dimensions.lines=1" | 528 | -o "window.dimensions.lines=1" |
| 518 | -o "window.position.x=-0" | 529 | -o "window.position.x=-0" |
| 519 | -o "window.position.y=0" | 530 | -o "window.position.y=0" |
| 531 | -o "window.opacity=0.6" | ||
| 520 | -o "font.size=40" | 532 | -o "font.size=40" |
| 521 | -e ~/helper/bin/unix/countdown.sh | 533 | -e ~/helper/bin/unix/countdown.sh |
| 522 | </command> | 534 | </command> |
| 523 | </action> | 535 | </action> |
| 524 | </keybind> | 536 | </keybind> |
| 537 | <keybind key="W-S-y"> | ||
| 538 | <action name="ForEach"> | ||
| 539 | <query target="default"> | ||
| 540 | <title type="exact">COUNTDOWN</title> | ||
| 541 | </query> | ||
| 542 | <then> | ||
| 543 | <action name="Focus"/> | ||
| 544 | </then> | ||
| 545 | </action> | ||
| 546 | </keybind> | ||
| 525 | <keybind key="W-f"> | 547 | <keybind key="W-f"> |
| 526 | <action name="Execute"> | 548 | <action name="Execute"> |
| 527 | <command>thunar ~/Downloads</command> | 549 | <command>thunar ~/Downloads</command> |
| @@ -1015,12 +1037,16 @@ | |||
| 1015 | <x>-0</x> | 1037 | <x>-0</x> |
| 1016 | <y>-0</y> | 1038 | <y>-0</y> |
| 1017 | </position> | 1039 | </position> |
| 1040 | <layer>above</layer> | ||
| 1041 | <skip_taskbar>yes</skip_taskbar> | ||
| 1018 | </application> | 1042 | </application> |
| 1019 | <application title="COUNTDOWN"> | 1043 | <application title="COUNTDOWN"> |
| 1020 | <position force="yes"> | 1044 | <position force="yes"> |
| 1021 | <x>-0</x> | 1045 | <x>-0</x> |
| 1022 | <y>-0</y> | 1046 | <y>-0</y> |
| 1023 | </position> | 1047 | </position> |
| 1048 | <layer>above</layer> | ||
| 1049 | <skip_taskbar>yes</skip_taskbar> | ||
| 1024 | </application> | 1050 | </application> |
| 1025 | <!-- | 1051 | <!-- |
| 1026 | # this is an example with comments through out. use these to make your | 1052 | # this is an example with comments through out. use these to make your |
diff --git a/bin/unix/countdown.sh b/bin/unix/countdown.sh index 683949e..ca6b5d6 100755 --- a/bin/unix/countdown.sh +++ b/bin/unix/countdown.sh | |||
| @@ -1,19 +1,34 @@ | |||
| 1 | #! /bin/bash | 1 | #! /bin/bash |
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | 2 | # Ref: https://superuser.com/questions/611538/611582#611582 |
| 3 | 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 | ||
| 4 | tput civis | 10 | tput civis |
| 11 | |||
| 12 | # Wait user input | ||
| 5 | read -p '? ' input | 13 | read -p '? ' input |
| 6 | 14 | ||
| 15 | # Modify input to fit the format that `date` can read | ||
| 16 | # s -> sec | ||
| 17 | # m -> min | ||
| 18 | # h -> hour | ||
| 7 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | 19 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" |
| 8 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | 20 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" |
| 9 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | 21 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" |
| 10 | 22 | ||
| 11 | |||
| 12 | start=$(date +%s -d "$input") | 23 | start=$(date +%s -d "$input") |
| 13 | while [ "$start" -ge $(date +%s) ]; do | 24 | while [ "$start" -ge $(date +%s) ]; do |
| 14 | ## Is this more than 24h away? | 25 | ## Is this more than 24h away? |
| 15 | time="$(( $start - `date +%s` ))" | 26 | time="$(( $start - `date +%s` ))" |
| 16 | printf '%s\r' "$(date -u -d "@$time" +%H:%M:%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 | ||
| 17 | sleep 0.3 | 32 | sleep 0.3 |
| 18 | done | 33 | done |
| 19 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | 34 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" |
diff --git a/bin/unix/stopwatch.sh b/bin/unix/stopwatch.sh index 70f6b0c..6b76c26 100755 --- a/bin/unix/stopwatch.sh +++ b/bin/unix/stopwatch.sh | |||
| @@ -1,9 +1,21 @@ | |||
| 1 | #! /bin/bash | 1 | #! /bin/bash |
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | 2 | # Ref: https://superuser.com/questions/611538/611582#611582 |
| 3 | 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 | ||
| 4 | tput civis | 10 | tput civis |
| 11 | |||
| 12 | # Wait user input | ||
| 5 | read -p '? ' input | 13 | read -p '? ' input |
| 6 | 14 | ||
| 15 | # Modify input to fit the format that `date` can read | ||
| 16 | # s -> sec | ||
| 17 | # m -> min | ||
| 18 | # h -> hour | ||
| 7 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | 19 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" |
| 8 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | 20 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" |
| 9 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | 21 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" |
| @@ -14,7 +26,12 @@ given=$(date +%s -d "$input") | |||
| 14 | stop=$(( $given - $start )) | 26 | stop=$(( $given - $start )) |
| 15 | while [ $time -ne $stop ]; do | 27 | while [ $time -ne $stop ]; do |
| 16 | time="$(( $(date +%s) - $start ))" | 28 | time="$(( $(date +%s) - $start ))" |
| 17 | printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)" | 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 | ||
| 18 | sleep 0.3 | 34 | sleep 0.3 |
| 19 | done | 35 | done |
| 36 | |||
| 20 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | 37 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" |