{"thread":{"id":"24736","subject":"Re: [PATCH] completion: make compatible with zsh","startedAt":"2010-08-14T03:17:32Z","lastAt":"2010-08-16T01:43:39Z","messageCount":5,"participants":["Mark Lodato","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"148071","messageId":"AANLkTikrE1Fy2Trz6b4MSJk6KzMvH9gDoYWwOEgYkFRJ@mail.gmail.com","threadId":"24736","inReplyTo":"1280890654-18486-1-git-send-email-lodatom@gmail.com","subject":"Re: [PATCH] completion: make compatible with zsh","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2010-08-14T03:17:32Z","receivedAt":"2010-08-14T03:17:32Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"On Tue, Aug 3, 2010 at 10:57 PM, Mark Lodato <lodatom@gmail.com> wrote:\n> Modify git-completion.bash to work with both bash and zsh.  Most code\n> works fine, but a few things need tweaking.  Where possible, code is\n> written in such a way that both shells interpret fine, but some areas\n> need special-casing.\n\nIs there any interest in this patch, or anything I could do that would\nmake it more likely to be accepted?  Perhaps at least some of these\nchanges could be implemented.\n\nThanks,\nMark\n"},{"id":"148072","messageId":"AANLkTimknF-m4_TYt+-vBBW0e3A-DY1nY93k7mPybdaD@mail.gmail.com","threadId":"24736","inReplyTo":"AANLkTikrE1Fy2Trz6b4MSJk6KzMvH9gDoYWwOEgYkFRJ@mail.gmail.com","subject":"Re: [PATCH] completion: make compatible with zsh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-14T03:23:32Z","receivedAt":"2010-08-14T03:23:32Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Aug 14, 2010 at 03:17, Mark Lodato <lodatom@gmail.com> wrote:\n> On Tue, Aug 3, 2010 at 10:57 PM, Mark Lodato <lodatom@gmail.com> wrote:\n>> Modify git-completion.bash to work with both bash and zsh.  Most code\n>> works fine, but a few things need tweaking.  Where possible, code is\n>> written in such a way that both shells interpret fine, but some areas\n>> need special-casing.\n>\n> Is there any interest in this patch, or anything I could do that would\n> make it more likely to be accepted?  Perhaps at least some of these\n> changes could be implemented.\n\nWhat's the Message-ID for that patch? I can't find it in my mailbox or\nin a public archive (via Google).\n"},{"id":"148073","messageId":"1281757237-32656-1-git-send-email-lodatom@gmail.com","threadId":"24736","inReplyTo":"AANLkTimknF-m4_TYt+-vBBW0e3A-DY1nY93k7mPybdaD@mail.gmail.com","subject":"[PATCH] completion: make compatible with zsh","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2010-08-14T03:40:37Z","receivedAt":"2010-08-14T03:40:37Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"Modify git-completion.bash to work with both bash and zsh.  Most code\nworks fine, but a few things need tweaking.  Where possible, code is\nwritten in such a way that both shells interpret fine, but some areas\nneed special-casing.\n\ndeclare -F\n    Zsh doesn't have the same 'declare -F' as bash, but 'declare -f'\n    is the same, and it works just as well for our purposes.\n\n${var:2}\n    Zsh uses $var[3,-1] to trim the first two characters.  There is no\n    way to write cross-shell code to accomplish this, so we must wrap\n    this in a check for zsh.\n\nfor (( n=1; \"$n\" ... ))\n    Zsh does not allow \"$var\" in arithmetic loops.  Instead, pre-compute\n    the endpoint and use the variables without $'s or quotes.\n\nshopt\n    Zsh uses 'setopt', which has a different syntax than 'shopt.  Since\n    'shopt' is used infrequently in git-completion, we provide\n    a bare-bones emulation.\n\nemulate -L bash\nKSH_TYPESET\n    Zsh offers bash emulation, which turns on a set of features to\n    closely resemble bash; in particular, this turns on SH_WORDSPLIT.\n    We also need to set KSH_TYPESET, to fix \"local var=$(echo foo bar)\"\n    issues.\n\nThe last set of options are turned on only in _git and _gitk.  Some of\nthe sub-functions may not work correctly if called directly.\n\nSigned-off-by: Mark Lodato <lodatom@gmail.com>\n---\n\nOn Fri, Aug 13, 2010 at 11:23 PM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n> On Sat, Aug 14, 2010 at 03:17, Mark Lodato <lodatom@gmail.com> wrote:\n>> On Tue, Aug 3, 2010 at 10:57 PM, Mark Lodato <lodatom@gmail.com> wrote:\n>>> Modify git-completion.bash to work with both bash and zsh.  Most code\n>>> works fine, but a few things need tweaking.  Where possible, code is\n>>> written in such a way that both shells interpret fine, but some areas\n>>> need special-casing.\n>>\n>> Is there any interest in this patch, or anything I could do that would\n>> make it more likely to be accepted?  Perhaps at least some of these\n>> changes could be implemented.\n>\n> What's the Message-ID for that patch? I can't find it in my mailbox or\n> in a public archive (via Google).\n\nThanks for letting me know.\n\nIt appears that my initial message didn't go through.  I used the --to\nargument with 'git format-patch', but 'git send-email' didn't seem to\nparse it properly.  It stuck an empty \"To:\" line at the normal position,\nand then put an additional \"To: git@vger.kernel.org\" at the bottom of\nthe headers.  Gmail must not have liked this.\n\nSo, here's another shot.  I am not too familiar with how the completion\nworks, so the changed parts ought to be tested on both zsh and bash.\nAny suggestions on how to do so - or results from doing so - would be\ngreatly appreciated.\n\nI tried to make as few changes to the main part of the script as\npossible, so that zsh compatibility does not get in the way of normal\ndevelopment.  If anyone has any suggestions for improvement, please let\nme know.\n\nIf this should be split into separate patches, I can do that.  Each\nchange is so small, I thought it would make more sense to roll them all\ninto one.\n\n\n contrib/completion/git-completion.bash |   53 +++++++++++++++++++++++++++++---\n 1 files changed, 48 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6756990..dde796e 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -137,12 +137,19 @@ __git_ps1_show_upstream ()\n \tsvn*)\n \t\t# get the upstream from the \"git-svn-id: ...\" in a commit message\n \t\t# (git-svn uses essentially the same procedure internally)\n-\t\tlocal svn_upstream=($(git log --first-parent -1 \\\n-\t\t\t\t\t--grep=\"^git-svn-id: \\(${svn_url_pattern:2}\\)\" 2>/dev/null))\n+\t\tlocal svn_upstream pattern n_stop\n+\t\tif [[ -n $ZSH_VERSION ]]; then\n+\t\t\tpattern=\"$svn_url_pattern[3,-1]\"\n+\t\telse\n+\t\t\tpattern=\"${svn_url_pattern:2}\"\n+\t\tfi\n+\t\tsvn_upstream=($(git log --first-parent -1 \\\n+\t\t\t\t--grep=\"^git-svn-id: \\($pattern\\)\" 2>/dev/null))\n \t\tif [[ 0 -ne ${#svn_upstream[@]} ]]; then\n \t\t\tsvn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]}\n \t\t\tsvn_upstream=${svn_upstream%@*}\n-\t\t\tfor ((n=1; \"$n\" <= \"${#svn_remote[@]}\"; ++n)); do\n+\t\t\tn_stop=\"${#svn_remote[@]}\"\n+\t\t\tfor ((n=1; n <= n_stop; ++n)); do\n \t\t\t\tsvn_upstream=${svn_upstream#${svn_remote[$n]}}\n \t\t\tdone\n \n@@ -2339,6 +2346,11 @@ _git ()\n {\n \tlocal i c=1 command __git_dir\n \n+\tif [[ -n $ZSH_VERSION ]]; then\n+\t\temulate -L bash\n+\t\tsetopt KSH_TYPESET\n+\tfi\n+\n \twhile [ $c -lt $COMP_CWORD ]; do\n \t\ti=\"${COMP_WORDS[c]}\"\n \t\tcase \"$i\" in\n@@ -2372,17 +2384,22 @@ _git ()\n \tfi\n \n \tlocal completion_func=\"_git_${command//-/_}\"\n-\tdeclare -F $completion_func >/dev/null && $completion_func && return\n+\tdeclare -f $completion_func >/dev/null && $completion_func && return\n \n \tlocal expansion=$(__git_aliased_command \"$command\")\n \tif [ -n \"$expansion\" ]; then\n \t\tcompletion_func=\"_git_${expansion//-/_}\"\n-\t\tdeclare -F $completion_func >/dev/null && $completion_func\n+\t\tdeclare -f $completion_func >/dev/null && $completion_func\n \tfi\n }\n \n _gitk ()\n {\n+\tif [[ -n $ZSH_VERSION ]]; then\n+\t\temulate -L bash\n+\t\tsetopt KSH_TYPESET\n+\tfi\n+\n \t__git_has_doubledash && return\n \n \tlocal cur=\"${COMP_WORDS[COMP_CWORD]}\"\n@@ -2417,3 +2434,29 @@ if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \\\n \t|| complete -o default -o nospace -F _git git.exe\n fi\n+\n+if [[ -z $ZSH_VERSION ]]; then\n+\tshopt () {\n+\t\tlocal option\n+\t\tif [ $# -ne 2 ]; then\n+\t\t\techo \"USAGE: $0 (-q|-s|-u) <option>\" >&2\n+\t\t\treturn 1\n+\t\tfi\n+\t\tcase \"$2\" in\n+\t\tnullglob)\n+\t\t\toption=\"$2\"\n+\t\t\t;;\n+\t\t*)\n+\t\t\techo \"$0: invalid option: $2\" >&2\n+\t\t\treturn 1\n+\t\tesac\n+\t\tcase \"$1\" in\n+\t\t-q)\tsetopt | grep -q \"$option\" ;;\n+\t\t-u)\tunsetopt \"$option\" ;;\n+\t\t-s)\tsetopt \"$option\" ;;\n+\t\t*)\n+\t\t\techo \"$0: invalid flag: $1\" >&2\n+\t\t\treturn 1\n+\t\tesac\n+\t}\n+fi\n-- \n1.7.2.1\n"},{"id":"148074","messageId":"AANLkTiku8qgBcyYuy1eJDXsUsfMtSUuS525CVexTjRi9@mail.gmail.com","threadId":"24736","inReplyTo":"1281757237-32656-1-git-send-email-lodatom@gmail.com","subject":"Re: [PATCH] completion: make compatible with zsh","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-08-14T03:52:57Z","receivedAt":"2010-08-14T03:52:57Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Sat, Aug 14, 2010 at 03:40, Mark Lodato <lodatom@gmail.com> wrote:\n> On Fri, Aug 13, 2010 at 11:23 PM, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:\n>> On Sat, Aug 14, 2010 at 03:17, Mark Lodato <lodatom@gmail.com> wrote:\n>>> On Tue, Aug 3, 2010 at 10:57 PM, Mark Lodato <lodatom@gmail.com> wrote:\n>>>> Modify git-completion.bash to work with both bash and zsh.  Most code\n>>>> works fine, but a few things need tweaking.  Where possible, code is\n>>>> written in such a way that both shells interpret fine, but some areas\n>>>> need special-casing.\n>>>\n>>> Is there any interest in this patch, or anything I could do that would\n>>> make it more likely to be accepted?  Perhaps at least some of these\n>>> changes could be implemented.\n>>\n>> What's the Message-ID for that patch? I can't find it in my mailbox or\n>> in a public archive (via Google).\n>\n> Thanks for letting me know.\n>\n> It appears that my initial message didn't go through.  I used the --to\n> argument with 'git format-patch', but 'git send-email' didn't seem to\n> parse it properly.  It stuck an empty \"To:\" line at the normal position,\n> and then put an additional \"To: git@vger.kernel.org\" at the bottom of\n> the headers.  Gmail must not have liked this.\n>\n> So, here's another shot.  I am not too familiar with how the completion\n> works, so the changed parts ought to be tested on both zsh and bash.\n> Any suggestions on how to do so - or results from doing so - would be\n> greatly appreciated.\n>\n> I tried to make as few changes to the main part of the script as\n> possible, so that zsh compatibility does not get in the way of normal\n> development.  If anyone has any suggestions for improvement, please let\n> me know.\n>\n> If this should be split into separate patches, I can do that.  Each\n> change is so small, I thought it would make more sense to roll them all\n> into one.\n\nIt makes more sense as one patch.\n\nIt could use something in the comments at the top mentioning that this\nis supposed to work on zsh too, otherwise it looks good (but I'm not\nfamiliar with this code), it's a pretty minimal change for a big win.\n"},{"id":"148170","messageId":"AANLkTinoPRPqxPrzNHF5J595r_Oedy=LSPZNYdMhB+OD@mail.gmail.com","threadId":"24736","inReplyTo":"20100814212507.GD2372@burratino","subject":"Re: [PATCH] completion: make compatible with zsh","fromName":"Mark Lodato","fromEmail":"lodatom@gmail.com","sentAt":"2010-08-16T01:43:39Z","receivedAt":"2010-08-16T01:43:39Z","isPatch":true,"sender":{"key":"lodatom@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58860?v=4"},"body":"[original email was sent only to me]\n\nOn Sat, Aug 14, 2010 at 5:25 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Mark Lodato wrote:\n>\n>> ${var:2}\n>>     Zsh uses $var[3,-1] to trim the first two characters.  There is no\n>>     way to write cross-shell code to accomplish this, so we must wrap\n>>     this in a check for zsh.\n>\n> Maybe\n>\n>        ${var#??}\n\nGood idea.  I'll include this in the next version of the patch.\n"}]}