Here's one that uses the
--color option and allows you to use the
-n argument to specify a refresh interval.
cat <<EOF >&2
swatch - execute a program periodically with "watch". Supports aliases.
swatch [options] command
-n, --interval seconds (default: 1)
Specify update interval. The command will not allow quicker than
0.1 second interval.
if [ $# -eq 0 ]; then
case "$1" in
watch --color -n "$seconds" --exec bash -ic "$args || true"
I only needed color and timing support,
but I'm sure you could add more if you wanted.
The meat of the function is that it executes your command with bash directly in interactive mode and can thus use any aliases or commands that are normally available to you in bash.
I'm not that experienced with scripting so fair warning, your mileage may vary. Sometimes I have to press Ctrl+C a few times to get it to stop, but for what it's worth, I've been using it frequently for 6 months without issue.
Gist form: https://gist.github.com/ablacklama/550420c597f9599cf804d57dd6aad131