Skip to content

Commit

Permalink
feat(binaries): add lswatch
Browse files Browse the repository at this point in the history
  • Loading branch information
spywhere committed Nov 24, 2023
1 parent dce90e7 commit f394f51
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions binaries/lswatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

trap 'exit 0' INT

DIRECTORY="$PWD"
DELAY="1"

while true; do
case "$1" in
-d|--dir)
shift
DIRECTORY="$(realpath "$DIRECTORY/$1" 2>/dev/null)"
if test $? -ne 0; then
echo "No such file or directory: $1"
exit 1
fi
;;
-n|--delay)
shift
case "$1" in
-*)
echo "Delay must be a number, and greater than 0"
exit 1
;;
*)
if test "$(echo "$1" | bc)" != '0'; then
DELAY="$1"
else
echo "Delay must be a number, and greater than 0"
exit 1
fi
;;
esac
;;
*)
break
;;
esac
shift
done

if test -z "$1"; then
echo "No command given"
echo "Usage: $(basename "$0") [-n delay] [-d path] command args..."
exit 1
fi

while true; do
watch -Cwrt --chgexit -n "$DELAY" "command ls -oAT $DIRECTORY | sha256sum" 1>/dev/null && $@
done

0 comments on commit f394f51

Please sign in to comment.