Skip to content

Commit

Permalink
Add autocomplete support for the 'await' command in bash, fish, and z…
Browse files Browse the repository at this point in the history
…sh shells.
  • Loading branch information
slavaGanzin committed Aug 2, 2024
1 parent f5b6b91 commit 2b1dd4d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
25 changes: 25 additions & 0 deletions autocomplete.bash
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
25 changes: 25 additions & 0 deletions autocomplete.fish
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)'
32 changes: 32 additions & 0 deletions autocomplete.zsh
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

0 comments on commit 2b1dd4d

Please sign in to comment.