aboutsummaryrefslogtreecommitdiffstats
path: root/misc/bash_completion
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-06-14 19:43:58 +0200
committerMichael Muré <batolettre@gmail.com>2020-06-14 19:43:58 +0200
commit6fd7934f53e4e0fc16845a7928a1668a264b7857 (patch)
tree9a32a2f2adb62ae839cdeb3ca4d40e814d769829 /misc/bash_completion
parent4f15c87b4d93ae4e72647f4708c03052d78338ab (diff)
downloadgit-bug-6fd7934f53e4e0fc16845a7928a1668a264b7857.tar.gz
update cobra
Diffstat (limited to 'misc/bash_completion')
-rw-r--r--misc/bash_completion/git-bug66
1 files changed, 66 insertions, 0 deletions
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug
index bbebd28f..b86edb9f 100644
--- a/misc/bash_completion/git-bug
+++ b/misc/bash_completion/git-bug
@@ -36,6 +36,67 @@ __git-bug_contains_word()
return 1
}
+__git-bug_handle_go_custom_completion()
+{
+ __git-bug_debug "${FUNCNAME[0]}: cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}"
+
+ local out requestComp lastParam lastChar comp directive args
+
+ # Prepare the command to request completions for the program.
+ # Calling ${words[0]} instead of directly git-bug allows to handle aliases
+ args=("${words[@]:1}")
+ requestComp="${words[0]} __completeNoDesc ${args[*]}"
+
+ lastParam=${words[$((${#words[@]}-1))]}
+ lastChar=${lastParam:$((${#lastParam}-1)):1}
+ __git-bug_debug "${FUNCNAME[0]}: lastParam ${lastParam}, lastChar ${lastChar}"
+
+ if [ -z "${cur}" ] && [ "${lastChar}" != "=" ]; then
+ # If the last parameter is complete (there is a space following it)
+ # We add an extra empty parameter so we can indicate this to the go method.
+ __git-bug_debug "${FUNCNAME[0]}: Adding extra empty parameter"
+ requestComp="${requestComp} \"\""
+ fi
+
+ __git-bug_debug "${FUNCNAME[0]}: calling ${requestComp}"
+ # Use eval to handle any environment variables and such
+ out=$(eval "${requestComp}" 2>/dev/null)
+
+ # Extract the directive integer at the very end of the output following a colon (:)
+ directive=${out##*:}
+ # Remove the directive
+ out=${out%:*}
+ if [ "${directive}" = "${out}" ]; then
+ # There is not directive specified
+ directive=0
+ fi
+ __git-bug_debug "${FUNCNAME[0]}: the completion directive is: ${directive}"
+ __git-bug_debug "${FUNCNAME[0]}: the completions are: ${out[*]}"
+
+ if [ $((directive & 1)) -ne 0 ]; then
+ # Error code. No completion.
+ __git-bug_debug "${FUNCNAME[0]}: received error from custom completion go code"
+ return
+ else
+ if [ $((directive & 2)) -ne 0 ]; then
+ if [[ $(type -t compopt) = "builtin" ]]; then
+ __git-bug_debug "${FUNCNAME[0]}: activating no space"
+ compopt -o nospace
+ fi
+ fi
+ if [ $((directive & 4)) -ne 0 ]; then
+ if [[ $(type -t compopt) = "builtin" ]]; then
+ __git-bug_debug "${FUNCNAME[0]}: activating no file completion"
+ compopt +o default
+ fi
+ fi
+
+ while IFS='' read -r comp; do
+ COMPREPLY+=("$comp")
+ done < <(compgen -W "${out[*]}" -- "$cur")
+ fi
+}
+
__git-bug_handle_reply()
{
__git-bug_debug "${FUNCNAME[0]}"
@@ -99,6 +160,10 @@ __git-bug_handle_reply()
completions=("${commands[@]}")
if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
completions=("${must_have_one_noun[@]}")
+ elif [[ -n "${has_completion_function}" ]]; then
+ # if a go completion function is provided, defer to that function
+ completions=()
+ __git-bug_handle_go_custom_completion
fi
if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
completions+=("${must_have_one_flag[@]}")
@@ -1206,6 +1271,7 @@ __start_git-bug()
local commands=("git-bug")
local must_have_one_flag=()
local must_have_one_noun=()
+ local has_completion_function
local last_command
local nouns=()