Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[RFC/PATCH] completion: git: add fast mode



Using the official Git Bash completion script the completion is
blazingly fast.

We can optionally enable this mode if Git's official Bash completion script is
specified by the user.

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---

This patch is just to show how merging the gitfast/git zsh
wrapper/git-completion might look like.

 Completion/Unix/Command/_git | 125 +++++++++++++++++++++++++++++++++++
 1 file changed, 125 insertions(+)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 81a060e4d..9a307faad 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -39,6 +39,104 @@
 
 # TODO: There is still undocumented configurability in here.
 
+zstyle -s ":completion:*:*:git:*" bash-script git_bash_script
+
+if [ -n "$git_bash_script" ]; then
+
+local old_complete="$functions[complete]"
+functions[complete]=:
+COMP_WORDBREAKS=':'
+GIT_SOURCING_ZSH_COMPLETION=y . "$git_bash_script"
+functions[complete]="$old_complete"
+
+__gitcompadd ()
+{
+	compadd -Q -p "${2-}" -S "${3- }" ${@[4,-1]} -- ${=1} && _ret=0
+}
+
+__gitcomp ()
+{
+	emulate -L zsh
+
+	local cur_="${3-$cur}"
+
+	[[ "$cur_" == *= ]] && return
+
+	local c IFS=$' \t\n' sfx
+	for c in ${=1}; do
+		if [[ $c == "--" ]]; then
+			[[ "$cur_" == --no-* ]] && continue
+			__gitcompadd "--no-..."
+			break
+		fi
+
+		if [[ -z "${4-}" ]]; then
+			case $c in
+			*=) c="${c%=}"; sfx="=" ;;
+			*.) sfx="" ;;
+			*) sfx=" " ;;
+			esac
+		else
+			sfx="$4"
+		fi
+		__gitcompadd "$c" "${2-}" "$sfx" -q
+	done
+}
+
+__gitcomp_nl ()
+{
+	emulate -L zsh
+
+	IFS=$'\n' __gitcompadd "$1" "${2-}" "${4- }"
+}
+
+__gitcomp_file ()
+{
+	emulate -L zsh
+
+	compadd -f -p "${2-}" -- ${(f)1} && _ret=0
+}
+
+__gitcomp_direct ()
+{
+	__gitcomp_nl "$1" "" "" ""
+}
+
+__gitcomp_file_direct ()
+{
+	__gitcomp_file "$1" ""
+}
+
+__gitcomp_nl_append ()
+{
+	__gitcomp_nl "$@"
+}
+
+__gitcomp_direct_append ()
+{
+	__gitcomp_direct "$@"
+}
+
+__gitbash_complete_func ()
+{
+	local _ret=1
+	local cur cword prev
+
+	cur=${words[CURRENT]}
+	prev=${words[CURRENT-1]}
+	let cword=CURRENT-1
+
+	if (( $+functions[$1] )); then
+		compset -P '*[=:]'
+		emulate ksh -c $1
+		return _ret
+	else
+		return 1
+	fi
+}
+
+fi
+
 # HIGH-LEVEL COMMANDS (PORCELAIN)
 
 # Main Porcelain Commands
@@ -768,6 +866,11 @@ _git-diff () {
 
   case $state in
     (from-to-file)
+      if [ -n "$git_bash_script" ]; then
+        __gitbash_complete_func __git_complete_revlist && ret=0
+        return ret
+      fi
+
       # If "--" is part of $opt_args, this means it was specified before any
       # $words arguments. This means that no heads are specified in front, so
       # we need to complete *changed* files only.
@@ -953,6 +1056,11 @@ _git-format-patch () {
 
   case $state in
     (commit-or-commit-range)
+      if [ -n "$git_bash_script" ]; then
+        __gitbash_complete_func __git_complete_revlist && ret=0
+        return ret
+      fi
+
       if [[ -n ${opt_args[(I)--root]} ]]; then
         __git_commits && ret=0
       else
@@ -1183,6 +1291,13 @@ _git-log () {
     '1: :->first-commit-ranges-or-files' \
     '*: :->commit-ranges-or-files' && ret=0
 
+  if [ -n "$git_bash_script" ]; then
+    if [ -n "$state" ]; then
+      __gitbash_complete_func __git_complete_revlist && ret=0
+      return ret
+    fi
+  fi
+
   case $state in
     (first-commit-ranges-or-files)
       if [[ -n ${opt_args[(I)--]} ]]; then
@@ -1676,6 +1791,11 @@ _git-shortlog () {
       fi
       ;;
     (commit-range-or-file)
+      if [ -n "$git_bash_script" ]; then
+        __gitbash_complete_func __git_complete_revlist && ret=0
+        return ret
+      fi
+
       case $CURRENT in
         (1)
           if [[ -n ${opt_args[(I)--]} ]]; then
@@ -5412,6 +5532,11 @@ _git-rev-list () {
 
   case $state in
     (commit-or-path)
+      if [ -n "$git_bash_script" ]; then
+        __gitbash_complete_func __git_complete_revlist && ret=0
+        return ret
+      fi
+
       # TODO: What paths should we be completing here?
       if [[ -n ${opt_args[(I)--]} ]]; then
         __git_cached_files && ret=0
-- 
2.29.2





Messages sorted by: Reverse Date, Date, Thread, Author