From 09ea15eed73077e6846e33de7f6701406bac1d3b Mon Sep 17 00:00:00 2001 From: Matheus Albino Date: Wed, 1 Nov 2023 19:03:12 -0300 Subject: [PATCH] Add my-scripts/shell/swatchz.sh file --- my-scripts/shell/swatchz.sh | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 my-scripts/shell/swatchz.sh diff --git a/my-scripts/shell/swatchz.sh b/my-scripts/shell/swatchz.sh new file mode 100755 index 0000000..e54d4fb --- /dev/null +++ b/my-scripts/shell/swatchz.sh @@ -0,0 +1,46 @@ +swatch_usage() { + cat <&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 +} + +if [ $# -eq 0 ]; then + swatch_usage + exit 1 +fi + +seconds=1 +shell="$SHELL" + +while [ $# -gt 0 ]; do + case "$1" in + -n) + seconds="$2" + args="${@:3}" + shift 3 + ;; + -h) + swatch_usage + exit 1 + ;; + *) + args="${@:1}" + break + ;; + esac +done + +# Get the base name of the shell executable +shell_basename=$(basename "$shell") + +watch --color -n "$seconds" --exec "$shell" -ic "$args || true" +