From 5b13469628592c6cbd80c6b6792caa048ca08cc4 Mon Sep 17 00:00:00 2001 From: vitali87 Date: Fri, 27 Mar 2026 22:00:00 +0100 Subject: [PATCH 1/2] feat: add rn watch entity for file change monitoring --- lib/completions.sh | 3 ++- lib/run.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ test.sh | 24 ++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lib/completions.sh b/lib/completions.sh index aa5d9c7..cf5445b 100644 --- a/lib/completions.sh +++ b/lib/completions.sh @@ -20,7 +20,7 @@ _u7_complete_entities() { COMPREPLY=($(compgen -W "text slashes tabs perms owner --help" -- "$cur")) ;; run|rn) - COMPREPLY=($(compgen -W "job script check terminal --help" -- "$cur")) + COMPREPLY=($(compgen -W "job script check terminal watch --help" -- "$cur")) ;; esac } @@ -77,6 +77,7 @@ _u7_complete_args() { case "$entity" in check) COMPREPLY=($(compgen -W "syntax" -- "$cur")) ; _filedir ;; script) _filedir ;; + watch) _filedir ;; esac ;; esac diff --git a/lib/run.sh b/lib/run.sh index a25aa53..3b4d0b4 100644 --- a/lib/run.sh +++ b/lib/run.sh @@ -80,6 +80,47 @@ _u7_run() { fi ;; + watch) + local file="$1" + if [[ -z "$file" || "$2" != "run" ]]; then + echo "Usage: u7 rn watch run " + return 1 + fi + if [[ ! -e "$file" ]]; then + echo "File not found: $file" + return 1 + fi + shift 2 + local cmd="$*" + if [[ -z "$cmd" ]]; then + echo "Usage: u7 rn watch run " + return 1 + fi + if [[ "$_U7_DRY_RUN" == "1" ]]; then + echo "[dry-run] watch $file and run $cmd on change" + return 0 + fi + echo "Watching $file for changes... (Ctrl+C to stop)" + if command -v inotifywait &>/dev/null; then + while true; do + inotifywait -qq -e modify "$file" + eval "$cmd" + done + else + local last_mod + last_mod=$(stat -c %Y "$file" 2>/dev/null || stat -f %m "$file" 2>/dev/null) + while true; do + sleep 1 + local cur_mod + cur_mod=$(stat -c %Y "$file" 2>/dev/null || stat -f %m "$file" 2>/dev/null) + if [[ "$cur_mod" != "$last_mod" ]]; then + last_mod="$cur_mod" + eval "$cmd" + fi + done + fi + ;; + --help|-h) cat << 'EOF' u7 rn (run) - Execute/Control @@ -89,6 +130,7 @@ Usage: u7 rn [arguments] Entities: job in