diff --git a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions index 6459dcb..05b868d 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions +++ b/collections/ansible_collections/nullified/infrastructure/roles/common/templates/home/.zsh_functions @@ -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 +}