diff options
| -rwxr-xr-x | bin/unix/countdown.sh | 19 | ||||
| -rwxr-xr-x | bin/unix/stopwatch.sh | 20 | ||||
| -rw-r--r-- | zsh/zshrc | 8 |
3 files changed, 46 insertions, 1 deletions
diff --git a/bin/unix/countdown.sh b/bin/unix/countdown.sh new file mode 100755 index 0000000..683949e --- /dev/null +++ b/bin/unix/countdown.sh | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | ||
| 3 | |||
| 4 | tput civis | ||
| 5 | read -p '? ' input | ||
| 6 | |||
| 7 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | ||
| 8 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | ||
| 9 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | ||
| 10 | |||
| 11 | |||
| 12 | start=$(date +%s -d "$input") | ||
| 13 | while [ "$start" -ge $(date +%s) ]; do | ||
| 14 | ## Is this more than 24h away? | ||
| 15 | time="$(( $start - `date +%s` ))" | ||
| 16 | printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)" | ||
| 17 | sleep 0.3 | ||
| 18 | done | ||
| 19 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | ||
diff --git a/bin/unix/stopwatch.sh b/bin/unix/stopwatch.sh new file mode 100755 index 0000000..70f6b0c --- /dev/null +++ b/bin/unix/stopwatch.sh | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | # Ref: https://superuser.com/questions/611538/611582#611582 | ||
| 3 | |||
| 4 | tput civis | ||
| 5 | read -p '? ' input | ||
| 6 | |||
| 7 | [[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")" | ||
| 8 | [[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")" | ||
| 9 | [[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")" | ||
| 10 | |||
| 11 | time=0 | ||
| 12 | start=$(date +%s) | ||
| 13 | given=$(date +%s -d "$input") | ||
| 14 | stop=$(( $given - $start )) | ||
| 15 | while [ $time -ne $stop ]; do | ||
| 16 | time="$(( $(date +%s) - $start ))" | ||
| 17 | printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)" | ||
| 18 | sleep 0.3 | ||
| 19 | done | ||
| 20 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | ||
| @@ -14,7 +14,13 @@ source $SETTING_DIR/zsh/completion.zsh | |||
| 14 | source $SETTING_DIR/bin/init/load-settings.sh | 14 | source $SETTING_DIR/bin/init/load-settings.sh |
| 15 | 15 | ||
| 16 | # Reload zshrc | 16 | # Reload zshrc |
| 17 | alias .="source $ZDOTDIR/.zshrc" | 17 | function .() { |
| 18 | if [ $# -eq 0 ]; then | ||
| 19 | source $ZDOTDIR/.zshrc | ||
| 20 | else | ||
| 21 | source $@ | ||
| 22 | fi | ||
| 23 | } | ||
| 18 | 24 | ||
| 19 | # Options | 25 | # Options |
| 20 | setopt extended_glob | 26 | setopt extended_glob |