aboutsummaryrefslogtreecommitdiffstats
path: root/misc/zsh_completion
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-02-15 19:57:26 +0100
committerMichael Muré <batolettre@gmail.com>2022-02-15 19:57:26 +0100
commit9ed515fd546a6ed5e82b2b87d12f0241727d3f89 (patch)
treefdf45c882b3e8a32f4ff62e30a634b2bdd77d872 /misc/zsh_completion
parent05d73e1b5321c97cd05133b5ae49d1798bc2fe5d (diff)
downloadgit-bug-9ed515fd546a6ed5e82b2b87d12f0241727d3f89.tar.gz
update gqlgen
Diffstat (limited to 'misc/zsh_completion')
-rw-r--r--misc/zsh_completion/git-bug54
1 files changed, 36 insertions, 18 deletions
diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug
index e0a6d8a1..e7cbe9a9 100644
--- a/misc/zsh_completion/git-bug
+++ b/misc/zsh_completion/git-bug
@@ -18,7 +18,7 @@ _git-bug()
local shellCompDirectiveFilterFileExt=8
local shellCompDirectiveFilterDirs=16
- local lastParam lastChar flagPrefix requestComp out directive compCount comp lastComp
+ local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace
local -a completions
__git-bug_debug "\n========= starting completion logic =========="
@@ -86,7 +86,6 @@ _git-bug()
return
fi
- compCount=0
while IFS='\n' read -r comp; do
if [ -n "$comp" ]; then
# If requested, completions are returned with a description.
@@ -98,13 +97,17 @@ _git-bug()
local tab=$(printf '\t')
comp=${comp//$tab/:}
- ((compCount++))
__git-bug_debug "Adding completion: ${comp}"
completions+=${comp}
lastComp=$comp
fi
done < <(printf "%s\n" "${out[@]}")
+ if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
+ __git-bug_debug "Activating nospace."
+ noSpace="-S ''"
+ fi
+
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
# File extension filtering
local filteringCmd
@@ -122,7 +125,7 @@ _git-bug()
_arguments '*:filename:'"$filteringCmd"
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
# File completion for directories only
- local subDir
+ local subdir
subdir="${completions[1]}"
if [ -n "$subdir" ]; then
__git-bug_debug "Listing directories in $subdir"
@@ -131,29 +134,44 @@ _git-bug()
__git-bug_debug "Listing directories in ."
fi
+ local result
_arguments '*:dirname:_files -/'" ${flagPrefix}"
+ result=$?
if [ -n "$subdir" ]; then
popd >/dev/null 2>&1
fi
- elif [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ] && [ ${compCount} -eq 1 ]; then
- __git-bug_debug "Activating nospace."
- # We can use compadd here as there is no description when
- # there is only one completion.
- compadd -S '' "${lastComp}"
- elif [ ${compCount} -eq 0 ]; then
- if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
- __git-bug_debug "deactivating file completion"
+ return $result
+ else
+ __git-bug_debug "Calling _describe"
+ if eval _describe "completions" completions $flagPrefix $noSpace; then
+ __git-bug_debug "_describe found some completions"
+
+ # Return the success of having called _describe
+ return 0
else
- # Perform file completion
- __git-bug_debug "activating file completion"
- _arguments '*:filename:_files'" ${flagPrefix}"
+ __git-bug_debug "_describe did not find completions."
+ __git-bug_debug "Checking if we should do file completion."
+ if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
+ __git-bug_debug "deactivating file completion"
+
+ # We must return an error code here to let zsh know that there were no
+ # completions found by _describe; this is what will trigger other
+ # matching algorithms to attempt to find completions.
+ # For example zsh can match letters in the middle of words.
+ return 1
+ else
+ # Perform file completion
+ __git-bug_debug "Activating file completion"
+
+ # We must return the result of this command, so it must be the
+ # last command, or else we must store its result to return it.
+ _arguments '*:filename:_files'" ${flagPrefix}"
+ fi
fi
- else
- _describe "completions" completions $(echo $flagPrefix)
fi
}
# don't run the completion function when being source-ed or eval-ed
if [ "$funcstack[1]" = "_git-bug" ]; then
- _git-bug
+ _git-bug
fi