diff options
Diffstat (limited to '')
-rw-r--r-- | completions/timeout | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/completions/timeout b/completions/timeout index 32ff2e3..f5115d2 100644 --- a/completions/timeout +++ b/completions/timeout @@ -1,39 +1,38 @@ # timeout(1) completion -*- shell-script -*- -_timeout() +_comp_cmd_timeout() { - local cur prev words cword split i found=false - _init_completion -s || return + local cur prev words cword was_split comp_args i + _comp_initialize -s -- "$@" || return - for ((i = 1; i <= COMP_CWORD; i++)); do - if [[ ${COMP_WORDS[i]} != -* && ${COMP_WORDS[i - 1]} != = ]]; then - if $found; then - _command_offset $i - return - fi - found=true + local noargopts='!(-*|*[ks]*)' + for ((i = 1; i < cword; i++)); do + if [[ ${words[i]} != -* ]]; then + _comp_command_offset "$((i + 1))" + return fi - [[ ${COMP_WORDS[i]} == -@(-kill-after|-signal|!(-*)[ks]) ]] && ((i++)) + # shellcheck disable=SC2254 + [[ ${words[i]} == -@(-kill-after|-signal|${noargopts}[ks]) ]] && ((i++)) done + # shellcheck disable=SC2254 case $prev in - --help | --version | --kill-after | -!(-*)k) + --help | --version | --kill-after | -${noargopts}k) return ;; - --signal | -!(-*)s) - _signals + --signal | -${noargopts}s) + _comp_compgen_signals return ;; esac - $split && return + [[ $was_split ]] && return if [[ $cur == -* ]]; then - local opts=$(_parse_help "$1") - COMPREPLY=($(compgen -W '${opts:-$(_parse_usage "$1")}' -- "$cur")) + _comp_compgen_help || _comp_compgen_usage [[ ${COMPREPLY-} == *= ]] && compopt -o nospace fi } && - complete -F _timeout timeout + complete -F _comp_cmd_timeout timeout # ex: filetype=sh |