{"thread":{"id":"30382","subject":"[PATCH v3] completion: add new zsh completion","startedAt":"2012-05-01T18:09:54Z","lastAt":"2012-05-01T18:09:54Z","messageCount":1,"participants":["Felipe Contreras"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"190456","messageId":"1335895794-3306-1-git-send-email-felipe.contreras@gmail.com","threadId":"30382","inReplyTo":null,"subject":"[PATCH v3] completion: add new zsh completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-05-01T18:09:54Z","receivedAt":"2012-05-01T18:09:54Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It seems there's always issues with zsh's bash completion emulation.\nI've tried to fix as many as I could and most of the fixes are already\nin the latest version of zsh, but still, there are issues.\n\nThere is no point going through all that pain; the emulation is easy to\nachieve, and this patch works better than zsh's emulation.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n\nv3:\n\n * Simplification\n * Avoid COMPREPLY; call compadd directly\n * Fix _get_comp_words_by_ref\n\n contrib/completion/git-completion.zsh |   97 +++++++++++++++++++++++++++++++++\n 1 file changed, 97 insertions(+)\n create mode 100644 contrib/completion/git-completion.zsh\n\ndiff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh\nnew file mode 100644\nindex 0000000..2f069cc\n--- /dev/null\n+++ b/contrib/completion/git-completion.zsh\n@@ -0,0 +1,97 @@\n+#compdef git gitk\n+\n+# zsh completion wrapper for git\n+#\n+# You need git's bash completion script installed somewhere, by default on the\n+# same directory as this script.\n+#\n+# If your script is on ~/.git-completion.sh instead, you can configure it on\n+# your ~/.zshrc:\n+#\n+#  zstyle ':completion:*:*:git:*' script ~/.git-completion.sh\n+#\n+# The recommended way to install this script is to copy to\n+# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:\n+#\n+#  fpath=(~/.zsh/completion $fpath)\n+\n+complete ()\n+{\n+\t# do nothing\n+\treturn 0\n+}\n+\n+zstyle -s \":completion:*:*:git:*\" script script\n+test -z \"$script\" && script=\"$(dirname ${funcsourcetrace[1]%:*})\"/git-completion.bash\n+ZSH_VERSION='' . \"$script\"\n+\n+_get_comp_words_by_ref ()\n+{\n+\temulate -L zsh\n+\twhile [ $# -gt 0 ]; do\n+\t\tcase \"$1\" in\n+\t\tcur)\n+\t\t\tcur=${_words[CURRENT]}\n+\t\t\t;;\n+\t\tprev)\n+\t\t\tprev=${_words[CURRENT-1]}\n+\t\t\t;;\n+\t\twords)\n+\t\t\twords=(\"${_words[@]}\")\n+\t\t\t;;\n+\t\tcword)\n+\t\t\t((cword = CURRENT - 1))\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+}\n+\n+__gitcompadd ()\n+{\n+\tcompadd -Q -S \"$3\" -P \"$2\" -p \"${(M)cur#*[=:]}\" -- ${=1} && _ret=0\n+}\n+\n+__gitcomp ()\n+{\n+\tlocal cur_=\"${3-$cur}\"\n+\n+\tcase \"$cur_\" in\n+\t--*=)\n+\t\t;;\n+\t*)\n+\t\tlocal IFS=$'\\n'\n+\t\t__gitcompadd \"$(__gitcomp_1 \"${1-}\")\" \"${2-}\" \"\"\n+\t\t;;\n+\tesac\n+}\n+\n+__gitcomp_nl ()\n+{\n+\tlocal IFS=$'\\n'\n+\t__gitcompadd \"$1\" \"${2-}\" \"${4- }\"\n+}\n+\n+do_wrap ()\n+{\n+\ttypeset -f $1 | sed \"s/${1} ()/${1}_wrap ()/\"\n+}\n+\n+eval \"$(do_wrap _git)\"\n+eval \"$(do_wrap _gitk)\"\n+\n+_git ()\n+{\n+\tlocal _ret=1\n+\tlocal -a _words\n+\t_words=( $words )\n+\t() {\n+\t\temulate -L ksh\n+\t\ttypeset -h words\n+\t\t_${service}_wrap\n+\t}\n+\tlet _ret && _default -S '' && _ret=0\n+\treturn _ret\n+}\n+\n+_git\n-- \n1.7.10\n"}]}