{"thread":{"id":"29470","subject":"[PATCH] completion: add new zsh completion","startedAt":"2012-01-30T00:01:39Z","lastAt":"2012-01-30T18:52:22Z","messageCount":7,"participants":["Felipe Contreras","Matthieu Moy","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"183273","messageId":"1327881699-25461-1-git-send-email-felipe.contreras@gmail.com","threadId":"29470","inReplyTo":null,"subject":"[PATCH] completion: add new zsh completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-30T00:01:39Z","receivedAt":"2012-01-30T00:01:39Z","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,\nafter I took a deep look at the code, I found many issues[1].\n\nSo, here is a kind of wrapper that does the same, but properly :)\n\nThis would also allow us to make fixes if necessary, since the code is\nsimple enough, and extend functionality.\n\n[1] http://article.gmane.org/gmane.comp.shells.zsh.devel/24290\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.zsh |  146 +++++++++++++++++++++++++++++++++\n 1 files changed, 146 insertions(+), 0 deletions(-)\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..15961df\n--- /dev/null\n+++ b/contrib/completion/git-completion.zsh\n@@ -0,0 +1,146 @@\n+#compdef git gitk\n+\n+compgen () {\n+\tlocal prefix suffix\n+\tlocal -a results\n+\twhile getopts \"W:P:S:\" opt\n+\tdo\n+\t\tcase $opt in\n+\t\tW)\n+\t\t\tresults=( ${(Q)~=OPTARG} )\n+\t\t\t;;\n+\t\tP)\n+\t\t\tprefix=\"$OPTARG\"\n+\t\t\t;;\n+\t\tS)\n+\t\t\tsuffix=\"$OPTARG\"\n+\t\t\t;;\n+\t\tesac\n+\tdone\n+\tprint -l -r -- \"$prefix${^results[@]}$suffix\"\n+}\n+\n+complete () {\n+\t# do nothing\n+\treturn 0\n+}\n+\n+ZSH_VERSION='' . /usr/share/git/completion/git-completion.bash\n+\n+_get_comp_words_by_ref ()\n+{\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\tcur=${_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+_bash_wrap ()\n+{\n+\tlocal -a COMPREPLY results _words\n+\t_words=( $words )\n+\t() {\n+\t\temulate -L sh\n+\t\tsetopt kshglob noshglob braceexpand nokshautoload\n+\t\ttypeset -h words\n+\t\tlocal cur words cword prev\n+\t\t_get_comp_words_by_ref -n =: cur words cword prev\n+\t\t$1\n+\t} $1\n+\tresults=( \"${^COMPREPLY[@]}\" )\n+\tlocal COMP_WORDBREAKS=\"\\\"'@><=;|&(:\"\n+\tlocal i start\n+\tlocal cur=\"${words[CURRENT]}\"\n+\ti=$(expr index \"$cur\" \"$COMP_WORDBREAKS\")\n+\tstart=\"${cur:0:$i}\"\n+\tcompadd -Q -S '' -p \"$start\" -a results && return 0\n+}\n+\n+_gitk ()\n+{\n+\t__git_has_doubledash && return\n+\n+\tlocal g=\"$(__gitdir)\"\n+\tlocal merge=\"\"\n+\tif [ -f \"$g/MERGE_HEAD\" ]; then\n+\t\tmerge=\"--merge\"\n+\tfi\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"\n+\t\t$__git_log_common_options\n+\t\t$__git_log_gitk_options\n+\t\t$merge\n+\t\t\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\t__git_complete_revlist\n+}\n+\n+_git ()\n+{\n+\tif [[ $service != git ]]\n+\tthen\n+\t\t_bash_wrap _$service\n+\t\treturn ret\n+\tfi\n+\n+\tlocal ret=1\n+\tlocal curcontext=\"$curcontext\" state state_descr line\n+\ttypeset -A opt_args\n+\n+\t_arguments -C \\\n+\t\t'(-p --paginate --no-pager)'{-p,--paginate}'[Pipe all output into ''less'']' \\\n+\t\t'(-p --paginate)--no-pager[Do not pipe git output into a pager]' \\\n+\t\t'--git-dir=-[Set the path to the repository]: :_directories' \\\n+\t\t'--bare[Treat the repository as a bare repository]' \\\n+\t\t'(- :)--version[Prints the git suite version]' \\\n+\t\t'--exec-path=-[Path to where your core git programs are installed]:: :_directories' \\\n+\t\t'--html-path[Print the path where git''s HTML documentation is installed]' \\\n+\t\t'--work-tree=-[Set the path to the working tree]: :_directories' \\\n+\t\t'--namespace=-[Set the git namespace]: :_directories' \\\n+\t\t'(- :)--help[Prints the synopsis and a list of the most commonly used commands]' \\\n+\t\t'(-): :->command' \\\n+\t\t'(-)*:: :->option-or-argument' && return 0\n+\n+\tcase $state in\n+\t(command)\n+\t\temulate sh -c __git_compute_porcelain_commands\n+\t\tlocal -a porcelain aliases\n+\t\tporcelain=( ${=__git_porcelain_commands} )\n+\t\taliases=( $(__git_aliases) )\n+\t\t_describe -t porcelain-commands 'porcelain commands' porcelain && ret=0\n+\t\t_describe -t aliases 'aliases' aliases && ret=0\n+\t\t;;\n+\t(option-or-argument)\n+\t\tlocal command=\"${words[1]}\"\n+\n+\t\tcompletion_func=\"_git_${command//-/_}\"\n+\t\tdeclare -f $completion_func >/dev/null && _bash_wrap $completion_func && return 0\n+\n+\t\tlocal expansion=$(__git_aliased_command \"$command\")\n+\t\tif [ -n \"$expansion\" ]; then\n+\t\t\tcompletion_func=\"_git_${expansion//-/_}\"\n+\t\t\tdeclare -f $completion_func >/dev/null && _bash_wrap $completion_func && return 0\n+\t\tfi\n+\t\t;;\n+\tesac\n+\n+\treturn ret\n+}\n+\n+_git\n-- \n1.7.8.3\n"},{"id":"183292","messageId":"vpqwr89d1p7.fsf@bauges.imag.fr","threadId":"29470","inReplyTo":"1327881699-25461-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] completion: add new zsh completion","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2012-01-30T08:39:00Z","receivedAt":"2012-01-30T08:39:00Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> +ZSH_VERSION='' . /usr/share/git/completion/git-completion.bash\n\nProbably stating the obvious, but this path shouldn't be hardcoded.\n\nSomething along the lines of\n\nZSH_VERSION='' . $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n\nshould do it (mostly untested, and written by a non-ZSH expert).\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"},{"id":"183303","messageId":"CAMP44s3QeZuXrR=UE4qvDadu66Cmi-txmSps8Ow24om27URxOg@mail.gmail.com","threadId":"29470","inReplyTo":"vpqwr89d1p7.fsf@bauges.imag.fr","subject":"Re: [PATCH] completion: add new zsh completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-30T10:59:40Z","receivedAt":"2012-01-30T10:59:40Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Mon, Jan 30, 2012 at 10:39 AM, Matthieu Moy\n<Matthieu.Moy@grenoble-inp.fr> wrote:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>\n>> +ZSH_VERSION='' . /usr/share/git/completion/git-completion.bash\n>\n> Probably stating the obvious, but this path shouldn't be hardcoded.\n>\n> Something along the lines of\n>\n> ZSH_VERSION='' . $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n>\n> should do it (mostly untested, and written by a non-ZSH expert).\n\nYes, it's hard-coded, because there's no way to know where is this\nfile. In my case, it's on ~/.git-completion.sh, and this one that I am\nproposing sits in ~/.zsh/completion/_zsh, so your proposal breaks\nthings completely for me.\n\nI will think about it, but I think for now, users of this script\nshould set that manually--if for some reason they don't want to use\nthe default.\n\nMaybe we should use zstyle so they can configure it on their .zshrc?\n\n-- \nFelipe Contreras\n"},{"id":"183304","messageId":"4F267AC9.1080407@viscovery.net","threadId":"29470","inReplyTo":"vpqwr89d1p7.fsf@bauges.imag.fr","subject":"Re: [PATCH] completion: add new zsh completion","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2012-01-30T11:11:05Z","receivedAt":"2012-01-30T11:11:05Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 1/30/2012 9:39, schrieb Matthieu Moy:\n> Felipe Contreras <felipe.contreras@gmail.com> writes:\n> \n>> +ZSH_VERSION='' . /usr/share/git/completion/git-completion.bash\n> \n> Probably stating the obvious, but this path shouldn't be hardcoded.\n> \n> Something along the lines of\n> \n> ZSH_VERSION='' . $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n> \n> should do it (mostly untested, and written by a non-ZSH expert).\n\nMoreover, if zsh is POSIX compliant, the value of ZSH_VERSION will be an\nempty string after this statement. That may or (more likely) may not be\nwhat you want.\n\n-- Hannes\n"},{"id":"183307","messageId":"CAMP44s2MmqEeyvztk8_3q9Ms_-su0D12GYD_LLWCKPAmb2ZKXg@mail.gmail.com","threadId":"29470","inReplyTo":"CAMP44s3QeZuXrR=UE4qvDadu66Cmi-txmSps8Ow24om27URxOg@mail.gmail.com","subject":"Re: [PATCH] completion: add new zsh completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-30T11:28:19Z","receivedAt":"2012-01-30T11:28:19Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Mon, Jan 30, 2012 at 12:59 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Mon, Jan 30, 2012 at 10:39 AM, Matthieu Moy\n> <Matthieu.Moy@grenoble-inp.fr> wrote:\n>> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>>\n>>> +ZSH_VERSION='' . /usr/share/git/completion/git-completion.bash\n>>\n>> Probably stating the obvious, but this path shouldn't be hardcoded.\n>>\n>> Something along the lines of\n>>\n>> ZSH_VERSION='' . $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n>>\n>> should do it (mostly untested, and written by a non-ZSH expert).\n>\n> Yes, it's hard-coded, because there's no way to know where is this\n> file. In my case, it's on ~/.git-completion.sh, and this one that I am\n> proposing sits in ~/.zsh/completion/_zsh, so your proposal breaks\n> things completely for me.\n>\n> I will think about it, but I think for now, users of this script\n> should set that manually--if for some reason they don't want to use\n> the default.\n>\n> Maybe we should use zstyle so they can configure it on their .zshrc?\n\nThis seems to do the trick:\n\nzstyle -s \":completion:$curcontext:\" script script\ntest -z \"$script\" && script=\"$(dirname\n${funcsourcetrace[1]%:*})\"/git-completion.bash\nZSH_VERSION='' . \"$script\"\n\n.zshrc:\nzstyle ':completion:*:*:git:*' script ~/.git-completion.sh\n\n-- \nFelipe Contreras\n"},{"id":"183309","messageId":"CAMP44s2B_WLmGryUv9Fitak67nWhp8Gpw3Ac-dApKB4KjYv1fQ@mail.gmail.com","threadId":"29470","inReplyTo":"4F267AC9.1080407@viscovery.net","subject":"Re: [PATCH] completion: add new zsh completion","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-01-30T11:32:24Z","receivedAt":"2012-01-30T11:32:24Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Mon, Jan 30, 2012 at 1:11 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:\n> Am 1/30/2012 9:39, schrieb Matthieu Moy:\n>> Felipe Contreras <felipe.contreras@gmail.com> writes:\n>>\n>>> +ZSH_VERSION='' . /usr/share/git/completion/git-completion.bash\n>>\n>> Probably stating the obvious, but this path shouldn't be hardcoded.\n>>\n>> Something along the lines of\n>>\n>> ZSH_VERSION='' . $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n>>\n>> should do it (mostly untested, and written by a non-ZSH expert).\n>\n> Moreover, if zsh is POSIX compliant, the value of ZSH_VERSION will be an\n> empty string after this statement. That may or (more likely) may not be\n> what you want.\n\nIt's not, only inside that script. Same in bash.\n\nAnd that's exactly what I want... I wan the git-completion.bash to\navoid any zsh hacks and workarounds.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"183357","messageId":"7vy5spauqh.fsf@alter.siamese.dyndns.org","threadId":"29470","inReplyTo":"4F267AC9.1080407@viscovery.net","subject":"Re: [PATCH] completion: add new zsh completion","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-01-30T18:52:22Z","receivedAt":"2012-01-30T18:52:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j.sixt@viscovery.net> writes:\n\n>> Something along the lines of\n>> \n>> ZSH_VERSION='' . $(dirname ${funcsourcetrace[1]%:*})/git-completion.bash\n>> \n>> should do it (mostly untested, and written by a non-ZSH expert).\n>\n> Moreover, if zsh is POSIX compliant, the value of ZSH_VERSION will be an\n> empty string after this statement. That may or (more likely) may not be\n> what you want.\n\nAs this split-file is about only zsh completion, it can be as non-POSIX as\nit wants, and it appears that zsh is not striving to be POSIX compliant,\njudging from Felipe's other messages.\n\nWhatever works for zsh is just fine.\n"}]}