Add my-scripts/shell/swatchz.sh file
This commit is contained in:
46
my-scripts/shell/swatchz.sh
Executable file
46
my-scripts/shell/swatchz.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
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
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user