extracted planktimer and built out osxtimer

This commit is contained in:
Wryn Wagner 2019-08-21 17:50:46 -06:00
parent 6d26e4d26b
commit 9e49551ef4
2 changed files with 109 additions and 21 deletions

View File

@ -1,32 +1,24 @@
#!/bin/bash
function planktimer() {
# dependencies: 'say' 'termdown' '.wryn/bash/rentdynamics'
message='Plank Time'
while true;
do
termdown 1h30m;
clear;
figlet "$message" | lolcat;
# update slack status
rdplank;
say -v $(say -v ? | sed -n "/en_/p" | sed "s/ .*//" | shuf -n 1) "$message";
read -n 1;
if [ $1 ]; then
termdown $1;
say -v $(say -v ? | sed -n "/en_/p" | sed "s/ .*//" | shuf -n 1) "done";
fi
rdstart;
done
function voicesed() { sed 's/\([^ ]*\) .*/\1/;'; }
function voicelist() { say -v ? | voicesed; }
function voicelistenglish() { say -v ? | grep 'en_' | voicesed; }
function voicerandom() { voicelistenglish | shuf -n 1; }
function voicelistnormal() {
voicelistenglish |
sed '/Trinoids/d;/Zarvox/d;/Deranged/d;/Hysterical/d;/Bahh/d;/Bubbles/d'
}
function voicerandomnormal() { voicelistnormal | shuf -n 1; }
function sayvoices() {
for voice in $(say -v ? | sed 's/ .*//' | sed 's/ News//');
do
for voice in $(voicelist); do
say -v "$voice" $(say -v ? | grep $voice | sed 's/[^#]*# //');
done
}
function sayone() {
voice=$(say -v ? | sed 's/ .*//' | sed 's/ News//' | shuf -n 1);
local voice=$(voicerandom);
say -v "$voice" $(say -v ? | grep $voice | sed 's/[^#]*# //');
}

96
bash/osx/osxtimer Normal file
View File

@ -0,0 +1,96 @@
#!/bin/bash
function osxtimer() {
# dependency check
#termdown --version >/dev/null 2>&1 || { echo osxtimer requires 'termdown'; exit 1; }
#lolcat --version >/dev/null 2>&1 || lolcatError='`lolcat` is not installed';
#figlet --version >/dev/null 2>&1 || figletError='`figlet` is not installed';
# set defaults
local msg;
local timestring='10s';
local voice;
local critical;
local dontsaycountdown;
local dontsaymessage;
local dowait;
local dontdisplaymessage;
local displayHelp;
unset OPTIND;
while getopts "MVTYhwm:t:c:v:" opt; do
case $opt in
m) msg=$OPTARG ;; # optional message
M) dontdisplaymessage=t ;; # don't display message (but maybe say it)
t) timestring=$OPTARG ;; # termdown countdown string
c) critical=$OPTARG ;; # optional critical seconds remaining
v) voice=$OPTARG ;; # optional voice for critical seconds remaining
V) voice=$(voicerandom) ;; # select random voice
T) dontsaycountdown=t; ;; # don't readout countdown
V) dontsaymessage=t; ;; # don't readout message after countdown
w) dowait=t; ;; # don't wait for user input after the timer
h) displayHelp=t; ;; # display help message
:) echo option -$OPTARG requires an argument; displayHelp=t;
;;
esac
done
unset OPTIND;
# exit on fail
if [ $displayHelp ]; then
printf "
Correct usage:
[-t]\t countdown amount as a timestring used in 'termdown'
[-m]\t display message after countdown is finished
[-c]\t critical seconds param for 'termdown'
[-v]\t 'say' voice used for reading the message and countdown
[-V]\t select random voice for message and timer readout
[-T]\t used with -v or -V :: don't readout the countdown
[-Y]\t used with -v or -V :: don't readout the message
[-w]\t wait for user input after the timer
\n";
return 1;
fi;
# verify that the voice exists
say -v ? | grep $voice >/dev/null 2>&1 || unset voice;
local termdownargs="$timestring ";
[[ $critical ]] && termdownargs="$termdownargs -c $critical";
[[ $voice ]] && [ -z $dontsaycountdown ] && termdownargs="$termdownargs -v $voice";
termdown $termdownargs;
[[ $msg ]] && [ -z $dontdisplaymessage ] && figlet "$msg" | lolcat;
[[ $voice ]] && [ -z $dontsaymessage ] && say -v "$voice" "$msg";
[[ $dowait ]] && read -n 1; # wait for user input
}
function rdexercise() {
local message='Plank time!';
local delay='1h30m';
local count;
# flagged arguments
unset OPTIND;
while getopts "m:t:c:" opt; do
case $opt in
m) message=$OPTARG ;; # optional message
t) timeout=$OPTARG ;; # termdown countdown string
c) count=$OPTARG ;; # length of exercise as a timestring
esac
done
unset OPTIND;
# operation loop
while true; do
rdstart >/dev/null 2>&1;
clear; osxtimer -VT -m "$message" -t "$delay";
rdplank >/dev/null 2>&1;
read -n 1; clear;
[[ $count ]] && osxtimer -c 10 -m "Done" -v "$(voicerandomnormal)" -t "$count";
done
}
alias planktimer='rdexercise -c';
alias pushuptimer='rdexercise -m "Push-up time!" -t "1h" -c';