Created
September 4, 2013 18:04
-
-
Save alexec/6440533 to your computer and use it in GitHub Desktop.
Run a command with as stopwatch, print the seconds as they pass. So you can track the progress of a command that lacks it's own progress bar.
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 | |
set -ue | |
BEGIN=$(date +%s) | |
BACK="\b\b\b\b" | |
($* ; touch /tmp/$$.done) & | |
OLDDIFF=0 | |
while true; do | |
NOW=$(date +%s) | |
DIFF=$(($NOW - $BEGIN)) | |
MINS=$(($DIFF / 60)) | |
SECS=$(($DIFF % 60)) | |
#only echo count if its different than the last time | |
if [ "$DIFF" != "$OLDDIFF" ] | |
then | |
#backspace 4 times to reset stopwatch position | |
#The '-e' enables \b to be interpreted correctly | |
#The '-n' avoids the newline character at the end | |
echo -ne $BACK | |
echo -ne $MINS:`printf %02d $SECS` | |
fi | |
OLDDIFF=DIFF | |
sleep 1s | |
if [ -e /tmp/$$.done ]; then | |
echo | |
exit | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment