Skip to content

Instantly share code, notes, and snippets.

@slashinfty
Forked from lillesvin/shplit.sh
Last active July 9, 2023 15:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slashinfty/86a232586dca8c4859e9078986e69307 to your computer and use it in GitHub Desktop.
Save slashinfty/86a232586dca8c4859e9078986e69307 to your computer and use it in GitHub Desktop.
Command line split timer - set up as an alias to easily run - removed text pipe option due to poor performance with obs
#!/bin/bash
alias stimer='shplit'
function shplit() {
FORMAT="%s.%2N"
STARTTIME=$(date +${FORMAT})
function format_duration {
printf "%.2f" $1
}
function tick_time {
DUR=$(format_duration $(bc <<< $(date +${FORMAT})-$STARTTIME))
PRETTY_DUR=$(date +%T.%2N -u -d "@${DUR}")
printf "\r%s " ${PRETTY_DUR}
}
function finish_up {
tick_time
echo
}
trap finish_up exit
echo "End timing with ctrl-c."
while true; do
tick_time
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment