Skip to content

Commit

Permalink
fix: unbound variables in bash completion
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
edentsai committed Jan 28, 2021
1 parent 9df156e commit bc9e5d4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bash_completions.go
Expand Up @@ -24,7 +24,7 @@ func writePreamble(buf *bytes.Buffer, name string) {
buf.WriteString(fmt.Sprintf(`
__%[1]s_debug()
{
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
fi
}
Expand Down Expand Up @@ -214,7 +214,7 @@ __%[1]s_handle_reply()
completions=("${commands[@]}")
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
completions+=("${must_have_one_noun[@]}")
elif [[ -n "${has_completion_function}" ]]; then
elif [[ -n "${has_completion_function:-}" ]]; then
# if a go completion function is provided, defer to that function
__%[1]s_handle_go_custom_completion
fi
Expand Down Expand Up @@ -334,7 +334,7 @@ __%[1]s_handle_command()
__%[1]s_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
local next_command
if [[ -n ${last_command} ]]; then
if [[ -n ${last_command:-} ]]; then
next_command="_${last_command}_${words[c]//:/__}"
else
if [[ $c -eq 0 ]]; then
Expand Down

0 comments on commit bc9e5d4

Please sign in to comment.