From f2621414ee5f2f601424c22f00e207903e3b6104 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 03:03:18 +0200 Subject: Merging upstream version 1:2.12.0. Signed-off-by: Daniel Baumann --- completions/dict | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'completions/dict') diff --git a/completions/dict b/completions/dict index f3426ff..f3b0cb6 100644 --- a/completions/dict +++ b/completions/dict @@ -1,47 +1,54 @@ # dict(1) completion -*- shell-script -*- -_dictdata() +_comp_cmd_dict__compgen_dictdata() { - dict $host $port $1 2>/dev/null | command sed -ne \ - 's/^[[:blank:]]\{1,\}\([^[:blank:]]*\).*$/\1/p' + # shellcheck disable=SC2086 + _comp_compgen_split -- "$( + "$@" 2>/dev/null | command sed -ne \ + 's/^[[:blank:]]\{1,\}\([^[:blank:]]*\).*$/\1/p' + )" } -_dict() +_comp_cmd_dict() { - local cur prev words cword - _init_completion || return + local cur prev words cword comp_args + _comp_initialize -- "$@" || return - local host port db i + local -a dict_command=("$1") + local host="" port="" db i + local noargopts='!(-*|*[hpdis]*)' for ((i = 1; i < cword; i++)); do + # shellcheck disable=SC2254 case ${words[i]} in - --host | -!(-*)h) + --host | -${noargopts}h) host=${words[++i]} - [[ -n $host ]] && host="-h $host" + [[ $host ]] && dict_command+=(-h "$host") ;; - --port | -!(-*)p) + --port | -${noargopts}p) port=${words[++i]} - [[ -n $port ]] && port="-p $port" + [[ $port ]] && dict_command+=(-p "$port") ;; - --database | -!(-*)d) + --database | -${noargopts}d) db=${words[++i]} - [[ -n $db ]] && host="-d $db" + [[ $db ]] && dict_command+=(-d "$db") ;; esac done if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) + _comp_compgen_help return fi + # shellcheck disable=SC2254 case $prev in - --database | -info | -!(-*)[di]) - COMPREPLY=($(compgen -W '$(_dictdata -D)' -- "$cur")) + --database | -info | -${noargopts}[di]) + _comp_cmd_dict__compgen_dictdata "${dict_command[@]}" -D return ;; - --strategy | -!(-*)s) - COMPREPLY=($(compgen -W '$(_dictdata -S)' -- "$cur")) + --strategy | -${noargopts}s) + _comp_cmd_dict__compgen_dictdata "${dict_command[@]}" -S return ;; esac @@ -52,13 +59,14 @@ _dict() # it down with grep if $cur looks like something that's safe to embed # in a pattern instead. if [[ $cur == +([-A-Za-z0-9/.]) ]]; then - COMPREPLY=($(compgen -W \ - '$(command grep "^${cur//./\\.}" $dictfile)' -- "$cur")) + _comp_compgen_split -- "$( + command grep "^${cur//./\\.}" "$dictfile" + )" else - COMPREPLY=($(compgen -W '$(cat $dictfile)' -- "$cur")) + _comp_compgen_split -- "$(cat "$dictfile")" fi fi } && - complete -F _dict -o default dict rdict + complete -F _comp_cmd_dict -o default dict rdict # ex: filetype=sh -- cgit v1.2.3