From b0125bc11353abd83bd57f718184d5e0221a30c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 29 Jun 2024 15:09:18 +1200 Subject: [PATCH] Manpage and completions --- completions/bash | 10 +++++++++- completions/elvish | 2 ++ completions/fish | 1 + completions/nu | 1 + completions/powershell | 2 ++ completions/zsh | 2 ++ crates/cli/src/args.rs | 18 +++++++++++++----- doc/watchexec.1 | 11 ++++++++++- doc/watchexec.1.md | 22 ++++++++++++++++++---- 9 files changed, 58 insertions(+), 11 deletions(-) diff --git a/completions/bash b/completions/bash index 31f6230a..c0598a89 100644 --- a/completions/bash +++ b/completions/bash @@ -19,7 +19,7 @@ _watchexec() { case "${cmd}" in watchexec) - opts="-w -W -c -o -r -s -d -p -n -E -1 -N -q -e -f -j -i -v -h -V --watch --watch-non-recursive --clear --on-busy-update --restart --signal --stop-signal --stop-timeout --map-signal --debounce --stdin-quit --no-vcs-ignore --no-project-ignore --no-global-ignore --no-default-ignore --no-discover-ignore --ignore-nothing --postpone --delay-run --poll --shell --no-environment --emit-events-to --only-emit-events --env --no-process-group --wrap-process --notify --color --timings --quiet --bell --project-origin --workdir --exts --filter --filter-file --filter-prog --ignore --ignore-file --fs-events --no-meta --print-events --manual --completions --verbose --log-file --help --version [COMMAND]..." + opts="-w -W -F -c -o -r -s -d -p -n -E -1 -N -q -e -f -j -i -v -h -V --watch --watch-non-recursive --watch-file --clear --on-busy-update --restart --signal --stop-signal --stop-timeout --map-signal --debounce --stdin-quit --no-vcs-ignore --no-project-ignore --no-global-ignore --no-default-ignore --no-discover-ignore --ignore-nothing --postpone --delay-run --poll --shell --no-environment --emit-events-to --only-emit-events --env --no-process-group --wrap-process --notify --color --timings --quiet --bell --project-origin --workdir --exts --filter --filter-file --filter-prog --ignore --ignore-file --fs-events --no-meta --print-events --manual --completions --verbose --log-file --help --version [COMMAND]..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 @@ -41,6 +41,14 @@ _watchexec() { COMPREPLY=($(compgen -f "${cur}")) return 0 ;; + --watch-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + -F) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; --clear) COMPREPLY=($(compgen -W "clear reset" -- "${cur}")) return 0 diff --git a/completions/elvish b/completions/elvish index 6af0bfd4..f36dd9ef 100644 --- a/completions/elvish +++ b/completions/elvish @@ -22,6 +22,8 @@ set edit:completion:arg-completer[watchexec] = {|@words| cand --watch 'Watch a specific file or directory' cand -W 'Watch a specific directory, non-recursively' cand --watch-non-recursive 'Watch a specific directory, non-recursively' + cand -F 'Watch files and directories from a file' + cand --watch-file 'Watch files and directories from a file' cand -c 'Clear screen before running command' cand --clear 'Clear screen before running command' cand -o 'What to do when receiving events while the command is running' diff --git a/completions/fish b/completions/fish index e35afa18..7c2d73b0 100644 --- a/completions/fish +++ b/completions/fish @@ -1,5 +1,6 @@ complete -c watchexec -s w -l watch -d 'Watch a specific file or directory' -r -F complete -c watchexec -s W -l watch-non-recursive -d 'Watch a specific directory, non-recursively' -r -F +complete -c watchexec -s F -l watch-file -d 'Watch files and directories from a file' -r -F complete -c watchexec -s c -l clear -d 'Clear screen before running command' -r -f -a "{clear '',reset ''}" complete -c watchexec -s o -l on-busy-update -d 'What to do when receiving events while the command is running' -r -f -a "{queue '',do-nothing '',restart '',signal ''}" complete -c watchexec -s s -l signal -d 'Send a signal to the process when it\'s still running' -r diff --git a/completions/nu b/completions/nu index bb860683..46784200 100644 --- a/completions/nu +++ b/completions/nu @@ -33,6 +33,7 @@ module completions { ...command: string # Command to run on changes --watch(-w): string # Watch a specific file or directory --watch-non-recursive(-W): string # Watch a specific directory, non-recursively + --watch-file(-F): string # Watch files and directories from a file --clear(-c): string@"nu-complete watchexec screen_clear" # Clear screen before running command --on-busy-update(-o): string@"nu-complete watchexec on_busy_update" # What to do when receiving events while the command is running --restart(-r) # Restart the process if it's still running diff --git a/completions/powershell b/completions/powershell index 7513880d..ebf21d0b 100644 --- a/completions/powershell +++ b/completions/powershell @@ -25,6 +25,8 @@ Register-ArgumentCompleter -Native -CommandName 'watchexec' -ScriptBlock { [CompletionResult]::new('--watch', 'watch', [CompletionResultType]::ParameterName, 'Watch a specific file or directory') [CompletionResult]::new('-W', 'W ', [CompletionResultType]::ParameterName, 'Watch a specific directory, non-recursively') [CompletionResult]::new('--watch-non-recursive', 'watch-non-recursive', [CompletionResultType]::ParameterName, 'Watch a specific directory, non-recursively') + [CompletionResult]::new('-F', 'F ', [CompletionResultType]::ParameterName, 'Watch files and directories from a file') + [CompletionResult]::new('--watch-file', 'watch-file', [CompletionResultType]::ParameterName, 'Watch files and directories from a file') [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'Clear screen before running command') [CompletionResult]::new('--clear', 'clear', [CompletionResultType]::ParameterName, 'Clear screen before running command') [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'What to do when receiving events while the command is running') diff --git a/completions/zsh b/completions/zsh index 07060969..8452b620 100644 --- a/completions/zsh +++ b/completions/zsh @@ -19,6 +19,8 @@ _watchexec() { '*--watch=[Watch a specific file or directory]:PATH:_files' \ '*-W+[Watch a specific directory, non-recursively]:PATH:_files' \ '*--watch-non-recursive=[Watch a specific directory, non-recursively]:PATH:_files' \ +'-F+[Watch files and directories from a file]:PATH:_files' \ +'--watch-file=[Watch files and directories from a file]:PATH:_files' \ '-c+[Clear screen before running command]' \ '--clear=[Clear screen before running command]' \ '-o+[What to do when receiving events while the command is running]:MODE:(queue do-nothing restart signal)' \ diff --git a/crates/cli/src/args.rs b/crates/cli/src/args.rs index e2583438..2b2e76e7 100644 --- a/crates/cli/src/args.rs +++ b/crates/cli/src/args.rs @@ -1263,11 +1263,19 @@ pub async fn get_args() -> Result<(Args, Option)> { args.project_origin = Some(project_origin.clone()); if let Some(watch_file) = args.watch_file.as_ref() { - let file = BufReader::new(File::open(watch_file).await.into_diagnostic()?); - let mut lines = file.lines(); - while let Ok(Some(line)) = lines.next_line().await { - args.recursive_paths.push(line.into()); - } + if watch_file == Path::new("-") { + let file = tokio::io::stdin(); + let mut lines = BufReader::new(file).lines(); + while let Ok(Some(line)) = lines.next_line().await { + args.recursive_paths.push(line.into()); + } + } else { + let file = File::open(watch_file).await.into_diagnostic()?; + let mut lines = BufReader::new(file).lines(); + while let Ok(Some(line)) = lines.next_line().await { + args.recursive_paths.push(line.into()); + } + }; } args.paths = take(&mut args.recursive_paths) diff --git a/doc/watchexec.1 b/doc/watchexec.1 index 86b9c87a..24045500 100644 --- a/doc/watchexec.1 +++ b/doc/watchexec.1 @@ -4,7 +4,7 @@ .SH NAME watchexec \- Execute commands when watched files change .SH SYNOPSIS -\fBwatchexec\fR [\fB\-w\fR|\fB\-\-watch\fR] [\fB\-W\fR|\fB\-\-watch\-non\-recursive\fR] [\fB\-c\fR|\fB\-\-clear\fR] [\fB\-o\fR|\fB\-\-on\-busy\-update\fR] [\fB\-r\fR|\fB\-\-restart\fR] [\fB\-s\fR|\fB\-\-signal\fR] [\fB\-\-stop\-signal\fR] [\fB\-\-stop\-timeout\fR] [\fB\-\-map\-signal\fR] [\fB\-d\fR|\fB\-\-debounce\fR] [\fB\-\-stdin\-quit\fR] [\fB\-\-no\-vcs\-ignore\fR] [\fB\-\-no\-project\-ignore\fR] [\fB\-\-no\-global\-ignore\fR] [\fB\-\-no\-default\-ignore\fR] [\fB\-\-no\-discover\-ignore\fR] [\fB\-\-ignore\-nothing\fR] [\fB\-p\fR|\fB\-\-postpone\fR] [\fB\-\-delay\-run\fR] [\fB\-\-poll\fR] [\fB\-\-shell\fR] [\fB\-n \fR] [\fB\-\-emit\-events\-to\fR] [\fB\-\-only\-emit\-events\fR] [\fB\-E\fR|\fB\-\-env\fR] [\fB\-\-no\-process\-group\fR] [\fB\-\-wrap\-process\fR] [\fB\-N\fR|\fB\-\-notify\fR] [\fB\-\-color\fR] [\fB\-\-timings\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-bell\fR] [\fB\-\-project\-origin\fR] [\fB\-\-workdir\fR] [\fB\-e\fR|\fB\-\-exts\fR] [\fB\-f\fR|\fB\-\-filter\fR] [\fB\-\-filter\-file\fR] [\fB\-j\fR|\fB\-\-filter\-prog\fR] [\fB\-i\fR|\fB\-\-ignore\fR] [\fB\-\-ignore\-file\fR] [\fB\-\-fs\-events\fR] [\fB\-\-no\-meta\fR] [\fB\-\-print\-events\fR] [\fB\-\-manual\fR] [\fB\-\-completions\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-\-log\-file\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fICOMMAND\fR] +\fBwatchexec\fR [\fB\-w\fR|\fB\-\-watch\fR] [\fB\-W\fR|\fB\-\-watch\-non\-recursive\fR] [\fB\-F\fR|\fB\-\-watch\-file\fR] [\fB\-c\fR|\fB\-\-clear\fR] [\fB\-o\fR|\fB\-\-on\-busy\-update\fR] [\fB\-r\fR|\fB\-\-restart\fR] [\fB\-s\fR|\fB\-\-signal\fR] [\fB\-\-stop\-signal\fR] [\fB\-\-stop\-timeout\fR] [\fB\-\-map\-signal\fR] [\fB\-d\fR|\fB\-\-debounce\fR] [\fB\-\-stdin\-quit\fR] [\fB\-\-no\-vcs\-ignore\fR] [\fB\-\-no\-project\-ignore\fR] [\fB\-\-no\-global\-ignore\fR] [\fB\-\-no\-default\-ignore\fR] [\fB\-\-no\-discover\-ignore\fR] [\fB\-\-ignore\-nothing\fR] [\fB\-p\fR|\fB\-\-postpone\fR] [\fB\-\-delay\-run\fR] [\fB\-\-poll\fR] [\fB\-\-shell\fR] [\fB\-n \fR] [\fB\-\-emit\-events\-to\fR] [\fB\-\-only\-emit\-events\fR] [\fB\-E\fR|\fB\-\-env\fR] [\fB\-\-no\-process\-group\fR] [\fB\-\-wrap\-process\fR] [\fB\-N\fR|\fB\-\-notify\fR] [\fB\-\-color\fR] [\fB\-\-timings\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-bell\fR] [\fB\-\-project\-origin\fR] [\fB\-\-workdir\fR] [\fB\-e\fR|\fB\-\-exts\fR] [\fB\-f\fR|\fB\-\-filter\fR] [\fB\-\-filter\-file\fR] [\fB\-j\fR|\fB\-\-filter\-prog\fR] [\fB\-i\fR|\fB\-\-ignore\fR] [\fB\-\-ignore\-file\fR] [\fB\-\-fs\-events\fR] [\fB\-\-no\-meta\fR] [\fB\-\-print\-events\fR] [\fB\-\-manual\fR] [\fB\-\-completions\fR] [\fB\-v\fR|\fB\-\-verbose\fR]... [\fB\-\-log\-file\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fB\-V\fR|\fB\-\-version\fR] [\fICOMMAND\fR] .SH DESCRIPTION Execute commands when watched files change. .PP @@ -55,6 +55,15 @@ Unlike \*(Aq\-w\*(Aq, folders watched with this option are not recursed into. This option can be specified multiple times to watch multiple directories non\-recursively. .TP +\fB\-F\fR, \fB\-\-watch\-file\fR=\fIPATH\fR +Watch files and directories from a file + +Each line in the file will be interpreted as if given to \*(Aq\-w\*(Aq. + +For more complex uses (like watching non\-recursively), use the argfile capability: build a file containing command\-line options and pass it to watchexec with `@path/to/argfile`. + +The special value \*(Aq\-\*(Aq will read from STDIN; this in incompatible with \*(Aq\-\-stdin\-quit\*(Aq. +.TP \fB\-c\fR, \fB\-\-clear\fR=\fIMODE\fR Clear screen before running command diff --git a/doc/watchexec.1.md b/doc/watchexec.1.md index 7e282118..f8891b3e 100644 --- a/doc/watchexec.1.md +++ b/doc/watchexec.1.md @@ -5,10 +5,11 @@ watchexec - Execute commands when watched files change # SYNOPSIS **watchexec** \[**-w**\|**\--watch**\] -\[**-W**\|**\--watch-non-recursive**\] \[**-c**\|**\--clear**\] -\[**-o**\|**\--on-busy-update**\] \[**-r**\|**\--restart**\] -\[**-s**\|**\--signal**\] \[**\--stop-signal**\] \[**\--stop-timeout**\] -\[**\--map-signal**\] \[**-d**\|**\--debounce**\] \[**\--stdin-quit**\] +\[**-W**\|**\--watch-non-recursive**\] \[**-F**\|**\--watch-file**\] +\[**-c**\|**\--clear**\] \[**-o**\|**\--on-busy-update**\] +\[**-r**\|**\--restart**\] \[**-s**\|**\--signal**\] +\[**\--stop-signal**\] \[**\--stop-timeout**\] \[**\--map-signal**\] +\[**-d**\|**\--debounce**\] \[**\--stdin-quit**\] \[**\--no-vcs-ignore**\] \[**\--no-project-ignore**\] \[**\--no-global-ignore**\] \[**\--no-default-ignore**\] \[**\--no-discover-ignore**\] \[**\--ignore-nothing**\] @@ -92,6 +93,19 @@ Unlike -w, folders watched with this option are not recursed into. This option can be specified multiple times to watch multiple directories non-recursively. +**-F**, **\--watch-file**=*PATH* + +: Watch files and directories from a file + +Each line in the file will be interpreted as if given to -w. + +For more complex uses (like watching non-recursively), use the argfile +capability: build a file containing command-line options and pass it to +watchexec with \`@path/to/argfile\`. + +The special value - will read from STDIN; this in incompatible with +\--stdin-quit. + **-c**, **\--clear**=*MODE* : Clear screen before running command