diff options
| author | Florian Fischer <florian.fl.fischer@fau.de> | 2016-02-07 17:46:21 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fl.fischer@fau.de> | 2016-02-07 17:46:21 +0100 |
| commit | 3fab3d5a5ea1c6f19caf887a95555042e32c42ff (patch) | |
| tree | 8f6c3009fe0e8c2a48a0e8005dd30ce663412ac3 /config | |
| parent | fba917d399ef557d2f0251f2dfa4fe5684a5893a (diff) | |
| download | dotfiles-3fab3d5a5ea1c6f19caf887a95555042e32c42ff.tar.gz dotfiles-3fab3d5a5ea1c6f19caf887a95555042e32c42ff.zip | |
improve timer function
1) add arg checking
2) introduce "-q" flag which skips the alarm
3) fix string replace when timer is finished
Diffstat (limited to 'config')
| -rw-r--r-- | config/fish/functions/timer.fish | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/config/fish/functions/timer.fish b/config/fish/functions/timer.fish index 7d8bb0e..f6f930b 100644 --- a/config/fish/functions/timer.fish +++ b/config/fish/functions/timer.fish @@ -1,17 +1,39 @@ function timer - if test (count $argv) -ne 1 - echo "Usage: timer <minutes to wait>" - return + + set usage "Usage: timer [-q] <minutes to wait>" + + if test (count $argv) -lt 1 + echo $usage + return 1 end - for i in (seq 1 $argv[1]) + + for i in (seq 1 (count $argv)) + if test $argv[$i] = "-q" + set quiet 1 + else if test $argv[$i] -gt 0 + set time $argv[$i] + else + echo $usage + return 1 + end + end + + if not set -q time + echo $usage + return 1 + end + + for i in (seq 1 $time) sleep 1m - echo (string replace -r '^0$' ready! (math $argv[1] - $i))m left + echo (string replace -r '0m left' ready! (echo (math $argv[1] - $i)m left)) end - while true - for i in (seq 1 20) - xkbbell - sleep 1 + if not set -q quiet + while true + for i in (seq 1 20) + xkbbell + sleep 1 + end + sleep 1m end - sleep 1m end end |
