Created
February 15, 2013 17:02
-
-
Save isakb/4961744 to your computer and use it in GitHub Desktop.
Simple watch variant
This file contains hidden or 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 | |
| # 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