Skip to content

Commit bc9e5d4

Browse files
committed
fix: unbound variables in bash completion
when `set -o nounset` in Bash, the warnings of unbound variables will break the bash completion. for example: ```sh $ set -o nounset $ my-cli <Tab>-bash: BASH_COMP_DEBUG_FILE: unbound variable ```
1 parent 9df156e commit bc9e5d4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

bash_completions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func writePreamble(buf *bytes.Buffer, name string) {
2424
buf.WriteString(fmt.Sprintf(`
2525
__%[1]s_debug()
2626
{
27-
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
27+
if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then
2828
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
2929
fi
3030
}
@@ -214,7 +214,7 @@ __%[1]s_handle_reply()
214214
completions=("${commands[@]}")
215215
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
216216
completions+=("${must_have_one_noun[@]}")
217-
elif [[ -n "${has_completion_function}" ]]; then
217+
elif [[ -n "${has_completion_function:-}" ]]; then
218218
# if a go completion function is provided, defer to that function
219219
__%[1]s_handle_go_custom_completion
220220
fi
@@ -334,7 +334,7 @@ __%[1]s_handle_command()
334334
__%[1]s_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
335335
336336
local next_command
337-
if [[ -n ${last_command} ]]; then
337+
if [[ -n ${last_command:-} ]]; then
338338
next_command="_${last_command}_${words[c]//:/__}"
339339
else
340340
if [[ $c -eq 0 ]]; then

0 commit comments

Comments
 (0)