Created
August 3, 2016 07:22
-
-
Save lillesvin/20edc4446817875787a415c3e345de6c to your computer and use it in GitHub Desktop.
Command line split timer that optionally uses a file as a pipe. You can have OBS read the contents of that file to display your timer in a video/stream if you don't want to just capture part of the terminal window. You can "split" by hitting Return/Enter (in the terminal) while the timer is running, and stop the timer with Ctrl-C (in the termina…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "${1}x" == "x" ]]; then | |
USE_PIPE=false | |
else | |
USE_PIPE=true | |
PIPE=${1} | |
fi | |
FORMAT="%s.%2N" | |
STARTTIME=$(date +${FORMAT}) | |
function show_info { | |
if [[ $USE_PIPE == true ]]; then | |
echo "Timer file: ${PIPE}" | |
fi | |
echo "End timing with ctrl-c." | |
} | |
# bc formats 0.nn as .nn which sucks | |
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} | |
if [[ $USE_PIPE == true ]]; then | |
echo ${PRETTY_DUR} > ${PIPE} | |
fi | |
} | |
function finish_up { | |
tick_time | |
echo | |
} | |
trap finish_up exit | |
show_info | |
while true; do | |
tick_time | |
if [[ $USE_PIPE == true ]]; then | |
sleep .1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment