-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add autocomplete support for the 'await' command in bash, fish, and z…
…sh shells.
- Loading branch information
1 parent
f5b6b91
commit 2b1dd4d
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
_await() { | ||
local cur prev opts | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
|
||
opts="--help --stdout -o --silent -V --fail -f --status -s --any -a --change -c --exec -e --interval -i --forever -F --service -S" | ||
|
||
case "${prev}" in | ||
--status|-s|--exec|-e|--interval|-i) | ||
COMPREPLY=($(compgen -f -- "${cur}")) | ||
return 0 | ||
;; | ||
esac | ||
|
||
if [[ ${cur} == -* ]]; then | ||
COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) | ||
return 0 | ||
fi | ||
|
||
COMPREPLY=($(compgen -c -- "${cur}")) | ||
return 0 | ||
} | ||
|
||
complete -F _await await |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function __fish_await_no_subcommand | ||
set -l cmd (commandline -opc) | ||
for i in $cmd | ||
switch $i | ||
case --help --stdout --silent --fail --status --any --change --exec --interval --forever --service | ||
return 1 | ||
end | ||
end | ||
return 0 | ||
end | ||
|
||
complete -c await -n '__fish_await_no_subcommand' -l help -d 'Print this help' | ||
complete -c await -n '__fish_await_no_subcommand' -l stdout -s o -d 'Print stdout of commands' | ||
complete -c await -n '__fish_await_no_subcommand' -l silent -s V -d 'Do not print spinners and commands' | ||
complete -c await -n '__fish_await_no_subcommand' -l fail -s f -d 'Waiting commands to fail' | ||
complete -c await -n '__fish_await_no_subcommand' -l status -s s -d 'Expected status [default: 0]' -r | ||
complete -c await -n '__fish_await_no_subcommand' -l any -s a -d 'Terminate if any of command return expected status' | ||
complete -c await -n '__fish_await_no_subcommand' -l change -s c -d 'Waiting for stdout to change and ignore status codes' | ||
complete -c await -n '__fish_await_no_subcommand' -l exec -s e -d 'Run some shell command on success' -r | ||
complete -c await -n '__fish_await_no_subcommand' -l interval -s i -d 'Milliseconds between one round of commands [default: 200]' -r | ||
complete -c await -n '__fish_await_no_subcommand' -l forever -s F -d 'Do not exit ever' | ||
complete -c await -n '__fish_await_no_subcommand' -l service -s S -d 'Create systemd user service with same parameters and activate it' | ||
|
||
# For command completion | ||
complete -c await -f -a '(__fish_complete_command)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Ensure compinit is loaded | ||
autoload -Uz compinit | ||
compinit | ||
|
||
# Define the completion function for 'await' | ||
_await() { | ||
_arguments -s -S \ | ||
'--help[Print this help]' \ | ||
'--stdout[Print stdout of commands]' \ | ||
'-o[Print stdout of commands]' \ | ||
'--silent[Do not print spinners and commands]' \ | ||
'-V[Do not print spinners and commands]' \ | ||
'--fail[Wait for commands to fail]' \ | ||
'-f[Wait for commands to fail]' \ | ||
'--status[Expected status (default: 0)]::status' \ | ||
'-s[Expected status (default: 0)]::status' \ | ||
'--any[Terminate if any command returns expected status]' \ | ||
'-a[Terminate if any command returns expected status]' \ | ||
'--change[Wait for stdout to change and ignore status codes]' \ | ||
'-c[Wait for stdout to change and ignore status codes]' \ | ||
'--exec[Run some shell command on success]::command:_command_names' \ | ||
'-e[Run some shell command on success]::command:_command_names' \ | ||
'--interval[Milliseconds between rounds of commands (default: 200)]::interval' \ | ||
'-i[Milliseconds between rounds of commands (default: 200)]::interval' \ | ||
'--forever[Do not exit ever]' \ | ||
'-F[Do not exit ever]' \ | ||
'--service[Create systemd user service with same parameters and activate it]' \ | ||
'-S[Create systemd user service with same parameters and activate it]' | ||
} | ||
|
||
# Register the completion function | ||
compdef _await await |