Last active
January 2, 2016 04:06
-
-
Save sinelaw/12b7957950c5103e7b46 to your computer and use it in GitHub Desktop.
In-place tail: prints the last output line of a command, overriding it in-place
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 -eu | |
LOG_FILE=$1 | |
SB="stdbuf -i0 -oL" | |
shift | |
tput sc | |
$@ 2>&1 | $SB tee $LOG_FILE | $SB cut -c-$(tput cols) | $SB sed -u 's/\(.\)/\\\1/g' | $SB xargs -0 -d'\n' -iyosi -n1 bash -c 'tput rc;tput el; printf "\r%s" yosi' | |
EXIT_CODE=${PIPESTATUS[0]} | |
tput rc;tput el;printf "\r" # Delete the last printed line | |
exit $EXIT_CODE | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment