aboutsummaryrefslogtreecommitdiffstats
path: root/misc/bash_completion
diff options
context:
space:
mode:
Diffstat (limited to 'misc/bash_completion')
-rw-r--r--misc/bash_completion/git-bug47
1 files changed, 28 insertions, 19 deletions
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug
index 8b303991..2320c1c0 100644
--- a/misc/bash_completion/git-bug
+++ b/misc/bash_completion/git-bug
@@ -2,7 +2,7 @@
__git-bug_debug()
{
- if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
+ if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
fi
}
@@ -112,7 +112,7 @@ __git-bug_handle_go_custom_completion()
$filteringCmd
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
# File completion for directories only
- local subDir
+ local subdir
# Use printf to strip any trailing newline
subdir=$(printf "%s" "${out[0]}")
if [ -n "$subdir" ]; then
@@ -165,13 +165,19 @@ __git-bug_handle_reply()
PREFIX=""
cur="${cur#*=}"
${flags_completion[${index}]}
- if [ -n "${ZSH_VERSION}" ]; then
+ if [ -n "${ZSH_VERSION:-}" ]; then
# zsh completion needs --flag= prefix
eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
fi
fi
fi
- return 0;
+
+ if [[ -z "${flag_parsing_disabled}" ]]; then
+ # If flag parsing is enabled, we have completed the flags and can return.
+ # If flag parsing is disabled, we may not know all (or any) of the flags, so we fallthrough
+ # to possibly call handle_go_custom_completion.
+ return 0;
+ fi
;;
esac
@@ -210,13 +216,13 @@ __git-bug_handle_reply()
fi
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
- if declare -F __git-bug_custom_func >/dev/null; then
- # try command name qualified custom func
- __git-bug_custom_func
- else
- # otherwise fall back to unqualified for compatibility
- declare -F __custom_func >/dev/null && __custom_func
- fi
+ if declare -F __git-bug_custom_func >/dev/null; then
+ # try command name qualified custom func
+ __git-bug_custom_func
+ else
+ # otherwise fall back to unqualified for compatibility
+ declare -F __custom_func >/dev/null && __custom_func
+ fi
fi
# available in bash-completion >= 2, not always present on macOS
@@ -250,7 +256,7 @@ __git-bug_handle_flag()
# if a command required a flag, and we found it, unset must_have_one_flag()
local flagname=${words[c]}
- local flagvalue
+ local flagvalue=""
# if the word contained an =
if [[ ${words[c]} == *"="* ]]; then
flagvalue=${flagname#*=} # take in as flagvalue after the =
@@ -269,7 +275,7 @@ __git-bug_handle_flag()
# keep flag value with flagname as flaghash
# flaghash variable is an associative array which is only supported in bash > 3.
- if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
+ if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
if [ -n "${flagvalue}" ] ; then
flaghash[${flagname}]=${flagvalue}
elif [ -n "${words[ $((c+1)) ]}" ] ; then
@@ -281,7 +287,7 @@ __git-bug_handle_flag()
# skip the argument to a two word flag
if [[ ${words[c]} != *"="* ]] && __git-bug_contains_word "${words[c]}" "${two_word_flags[@]}"; then
- __git-bug_debug "${FUNCNAME[0]}: found a flag ${words[c]}, skip the next argument"
+ __git-bug_debug "${FUNCNAME[0]}: found a flag ${words[c]}, skip the next argument"
c=$((c+1))
# if we are looking for a flags value, don't show commands
if [[ $c -eq $cword ]]; then
@@ -341,7 +347,7 @@ __git-bug_handle_word()
__git-bug_handle_command
elif __git-bug_contains_word "${words[c]}" "${command_aliases[@]}"; then
# aliashash variable is an associative array which is only supported in bash > 3.
- if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
+ if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
words[c]=${aliashash[${words[c]}]}
__git-bug_handle_command
else
@@ -1445,7 +1451,7 @@ _git-bug_root_command()
commands+=("show")
commands+=("status")
commands+=("termui")
- if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
+ if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
command_aliases+=("tui")
aliashash["tui"]="termui"
fi
@@ -1468,7 +1474,7 @@ _git-bug_root_command()
__start_git-bug()
{
- local cur prev words cword
+ local cur prev words cword split
declare -A flaghash 2>/dev/null || :
declare -A aliashash 2>/dev/null || :
if declare -F _init_completion >/dev/null 2>&1; then
@@ -1478,17 +1484,20 @@ __start_git-bug()
fi
local c=0
+ local flag_parsing_disabled=
local flags=()
local two_word_flags=()
local local_nonpersistent_flags=()
local flags_with_completion=()
local flags_completion=()
local commands=("git-bug")
+ local command_aliases=()
local must_have_one_flag=()
local must_have_one_noun=()
- local has_completion_function
- local last_command
+ local has_completion_function=""
+ local last_command=""
local nouns=()
+ local noun_aliases=()
__git-bug_handle_word
}