Skip to content

Instantly share code, notes, and snippets.

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs
Created October 8, 2022 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b6pzeusbc54tvhw5jgpyw8pwz2x6gs/e0414bf258863be921cc2c9156e24e59 to your computer and use it in GitHub Desktop.
Save b6pzeusbc54tvhw5jgpyw8pwz2x6gs/e0414bf258863be921cc2c9156e24e59 to your computer and use it in GitHub Desktop.
watch with color
#!/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
@b6pzeusbc54tvhw5jgpyw8pwz2x6gs
Copy link
Author

3초 주기 갱신 예제:

$ ./watch-color.sh -n 3 gt ls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment