Created
October 8, 2022 13:48
-
-
Save b6pzeusbc54tvhw5jgpyw8pwz2x6gs/e0414bf258863be921cc2c9156e24e59 to your computer and use it in GitHub Desktop.
watch with color
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/sh | |
# https://stackoverflow.com/a/69388883/5568628 | |
trap "tput cnorm" EXIT # unhide the cursor when the script exits or is interrupted | |
# simple interval parameter parsing, can be improved | |
INTERVAL=2 | |
case $1 in | |
-n|--interval) | |
INTERVAL="$2" | |
shift; shift | |
;; | |
esac | |
clear # clear the terminal | |
tput civis # invisible cursor, prevents cursor flicker | |
while true; do | |
tput cup 0 0 # move cursor to topleft, without clearing the previous output | |
sh -c "$*" # pass all arguments to sh, like the original watch | |
tput ed # clear all to the end of window, if the new output is shorter | |
sleep "$INTERVAL" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
3초 주기 갱신 예제: