Skip to content

Commit

Permalink
fix(dict): work around bash-4.3 ${v+"$@"} with custom IFS
Browse files Browse the repository at this point in the history
Bash < 4.4 has a bug that all the elements are connected with
`${v+"$@"}` when IFS does not contain whitespaces.  This becomes
problem with `${dict_options+"${dict_options[@]}"}`.  One way to fix
it is to set IFS=$' \t\n'.  In this patch, we instead change the use
of the array so that we do not have to rely on the ${v+"$@"} pattern.
  • Loading branch information
akinomyoga committed Aug 12, 2023
1 parent d0695d0 commit cc21298
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions completions/dict
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ _comp_cmd_dict()
local cur prev words cword comp_args
_comp_initialize -- "$@" || return

local -a dict_options=()
local -a dict_command=("$1")
local host="" port="" db i

local noargopts='!(-*|*[hpdis]*)'
Expand All @@ -23,15 +23,15 @@ _comp_cmd_dict()
case ${words[i]} in
--host | -${noargopts}h)
host=${words[++i]}
[[ $host ]] && dict_options+=(-h "$host")
[[ $host ]] && dict_command+=(-h "$host")
;;
--port | -${noargopts}p)
port=${words[++i]}
[[ $port ]] && dict_options+=(-p "$port")
[[ $port ]] && dict_command+=(-p "$port")
;;
--database | -${noargopts}d)
db=${words[++i]}
[[ $db ]] && dict_options+=(-d "$db")
[[ $db ]] && dict_command+=(-d "$db")
;;
esac
done
Expand All @@ -44,11 +44,11 @@ _comp_cmd_dict()
# shellcheck disable=SC2254
case $prev in
--database | -info | -${noargopts}[di])
_comp_cmd_dict__compgen_dictdata "$1" ${dict_options[@]+"${dict_options[@]}"} -D
_comp_cmd_dict__compgen_dictdata "${dict_command[@]}" -D
return
;;
--strategy | -${noargopts}s)
_comp_cmd_dict__compgen_dictdata "$1" ${dict_options[@]+"${dict_options[@]}"} -S
_comp_cmd_dict__compgen_dictdata "${dict_command[@]}" -S
return
;;
esac
Expand Down

0 comments on commit cc21298

Please sign in to comment.