Skip to content

Instantly share code, notes, and snippets.

@ablacklama
Last active February 8, 2023 01:09
Show Gist options
  • Save ablacklama/550420c597f9599cf804d57dd6aad131 to your computer and use it in GitHub Desktop.
Save ablacklama/550420c597f9599cf804d57dd6aad131 to your computer and use it in GitHub Desktop.
"watch" with alias, color, and timing support.
swatch_usage() {
cat <<EOF >&2
NAME
swatch - execute a program periodically with "watch". Supports aliases.
SYNOPSIS
swatch [options] command
OPTIONS
-n, --interval seconds (default: 1)
Specify update interval. The command will not allow quicker than
0.1 second interval.
EOF
}
swatch() {
if [ $# -eq 0 ]; then
swatch_usage
return 1
fi
seconds=1
case "$1" in
-n)
seconds="$2"
args=${*:3}
;;
-h)
swatch_usage
return 1
;;
*)
seconds=1
args=${*:1}
;;
esac
watch --color -n "$seconds" --exec bash -ic "$args || true"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment