Created
April 20, 2012 09:53
-
-
Save gammy/2427427 to your computer and use it in GitHub Desktop.
Poor man's watch
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 | |
# Poor man's "watch" | |
# Depends on bash, date, stty & head. | |
if [ ${#@} -lt 2 ]; then | |
echo "Usage: $(basename $0) <interval> <command>" | |
exit 1 | |
fi | |
t=$1 | |
shift | |
line="Every $t: $*" | |
clear | |
while true; do | |
# Calculate and draw top line with padding | |
ts=$(date) | |
dims=($(stty size)) | |
let padlen="${dims[1]} - (${#ts} + ${#line})" | |
padding=$(printf "%${padlen}s") | |
echo -e "\e[1m$line$padding$ts\e[0m\n" | |
# Execute command, show top $height rows, then sleep | |
let height=${dims[0]}-3 | |
$* | head -n $height | |
sleep $t | |
clear | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment