feat(common): add new timer function to ZSH
This commit is contained in:
parent
c3305093e4
commit
ff7c9d8b91
1 changed files with 23 additions and 0 deletions
|
@ -19,3 +19,26 @@ function kubeshell() {
|
|||
kubeBinary=$(command -v kubectl)
|
||||
"${kubeBinary}" exec -i -t -n "${namespace}" "${pod}" -c "${container}" "${@}" -- sh -c "clear; (zsh || bash || ash || sh)"
|
||||
}
|
||||
|
||||
function timer() {
|
||||
if [ $# != 1 ]; then
|
||||
printf "Missing duration in \`sleep\` format (e.g. 2m)\n"
|
||||
return 1
|
||||
fi
|
||||
read -r < <(sleep "$1" & echo $!)
|
||||
local sleep_pid="${REPLY}"
|
||||
trap 'kill "${sleep_pid}" ; return 0' SIGINT SIGTERM SIGQUIT
|
||||
|
||||
while :
|
||||
do
|
||||
if ! output_cmd=$(ps -o etime= -o args= -p "${sleep_pid}"); then
|
||||
echo -ne "Buzz!\033[0K\r\n"
|
||||
repeat "${TIMER_SOUND_REPEAT_COUNT:-3}" aplay "${TIMER_SOUND_FILE:-${HOME}/Music/Sounds/timer_done.wav}" &> /dev/null
|
||||
return 0
|
||||
else
|
||||
echo -ne "${output_cmd}\033[0K\r" | sed -E 's/\s+([0-9:]+)\s+sleep\s+(.+)/Elapsed: \1 of \2/'
|
||||
sleep "${TIMER_NOTIF_STEP:-1}"
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue