Skip to content

Instantly share code, notes, and snippets.

@sinelaw
Last active January 2, 2016 04:06
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sinelaw/12b7957950c5103e7b46 to your computer and use it in GitHub Desktop.
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
#!/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