From 652debfb47d66d2fd61c02f2ff23a0fc4c8f4832 Mon Sep 17 00:00:00 2001 From: Matheus Albino Brunhara Date: Mon, 25 Sep 2023 16:01:13 -0300 Subject: [PATCH] Add swatch.sh script --- my-scripts/shell/swatch.sh | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 my-scripts/shell/swatch.sh diff --git a/my-scripts/shell/swatch.sh b/my-scripts/shell/swatch.sh new file mode 100755 index 0000000..7ec71b7 --- /dev/null +++ b/my-scripts/shell/swatch.sh @@ -0,0 +1,40 @@ +# https://gist.github.com/ablacklama/550420c597f9599cf804d57dd6aad131 + +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 + 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"