Skip to content

Instantly share code, notes, and snippets.

@isakb
Created February 15, 2013 17:02
Show Gist options
  • Select an option

  • Save isakb/4961744 to your computer and use it in GitHub Desktop.

Select an option

Save isakb/4961744 to your computer and use it in GitHub Desktop.
Simple watch variant
#!/bin/bash
# A variant of watch, with smarter color support etc.
[[ $SLEEP ]] || SLEEP=2
cmd=$*
prev_output=""
while true ; do
output="$( $cmd 3>&1 2>&3 )"
if [[ "$output" != "$prev_output" ]] ; then
clear
HEIGHT=$( stty size | cut -d ' ' -f 1 )
echo -e "Watchish - every $SLEEP seconds: $cmd (Ctrl+C to abort)\n"
echo -e "$output" | head -n $(( HEIGHT - 2 ))
prev_output="$output"
fi
sleep $SLEEP
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment