{"thread":{"id":"32092","subject":"Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","startedAt":"2012-11-12T20:07:46Z","lastAt":"2012-11-20T21:07:58Z","messageCount":39,"participants":["Marc Khouzam","SZEDER Gábor","Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"202988","messageId":"CAFj1UpFd9X8Jq5o7B4m35i=merBDvOo4NOtwth=UnG2S5X_rGw@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpE6OtJEojaED1_DZJD0kU=nVsFE_w8xa0oJE-6auCU2rw@mail.gmail.com","subject":"Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-12T20:07:46Z","receivedAt":"2012-11-12T20:07:46Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"Hi,\n\nthis patch allows tcsh-users to get the benefits of the awesome\ngit-completion.bash script.  It could also help other shells do the same.\n\n==\n\nThe current tcsh-completion support for Git, as can be found on the\ninternet, takes the approach of defining the possible completions\nexplicitly.  This has the obvious draw-back to require constant\nupdating as the Git code base evolves.\n\nThe approach taken by this commit is to to re-use the advanced bash\ncompletion script and use its result for tcsh completion.  This is\nachieved by executing (versus sourcing) the bash script and\noutputting the completion result for tcsh consumption.\n\nThree solutions were looked at to implement this approach with (A)\nbeing retained:\n\n  A) Modifications:\n          git-completion.bash and new git-completion.tcsh\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash.\n     When being executed, the script will output the result of the\n     computed completion to be re-used elsewhere (e.g., in tcsh).\n     Pros:\n       1- allows the git-completion.bash script to easily be re-used\n       2- tcsh support is mostly isolated in git-completion.tcsh\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n\n  B) Modifications:\n          git-completion.bash\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash,\n     and sourced using tcsh.\n     Pros:\n       1- only requires the user to deal with a single file\n       2- maintenance more obvious for tcsh since it is entirely part\n          of the same git-completion.bash script.\n     Cons:\n       1- tcsh support could affect bash support as they share the\n          same script\n       2- small tcsh section must use syntax suitable for both tcsh\n          and bash and must be at the beginning of the script\n       3- requires the user to explicitly make the script executable\n          when using tcsh (for tcsh users only)\n       4- requires script to have a fixed name and location:\n          ${HOME}/.git-completion.sh (for tcsh users only)\n\n  C) Modifications:\n          New git-completion.tcsh\n\n     Provide a short tcsh script that converts git-completion.bash\n     into an executable script suitable to be used by tcsh.\n     Pros:\n       1- tcsh support is entirely isolated in git-completion.tcsh\n       2- new tcsh script can be as complex as needed\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n       3- sourcing the new script will generate a third script\n\nApproach (A) was selected to keep the tcsh completion support well\nisolated without introducing excessive complexity.\n\nSigned-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n\n==\n\nWith the changes applied, tcsh users should:\n\n#    1) Copy both this file and the bash completion script to your\n${HOME} directory\n#       using the names ${HOME}/.git-completion.tcsh and\n${HOME}/.git-completion.bash.\n#    2) Add the following line to your .tcshrc/.cshrc:\n#        source ${HOME}/.git-completion.tcsh\n\nThe code can be found on GitHub.\nOption (A):\nhttps://github.com/marckhouzam/git/commit/86d3a8e740ae85b4b4462c997a0fd969b1b2d24c\n\nOption (B):\nhttps://github.com/marckhouzam/git/commit/e64606541682eaf66c0a56aceff279ca6e1d06cd\n\nOption (C):\nhttps://github.com/marckhouzam/git/commit/59792455f1e6a98d3ffeb828f4cff1ded0e4ed37\n\nThanks\n\nMarc\n\n---\n contrib/completion/git-completion.bash |   53 +++++++++++++++++++++++++++++++-\n contrib/completion/git-completion.tcsh |   34 ++++++++++++++++++++\n 2 files changed, 86 insertions(+), 1 deletions(-)\n create mode 100755 contrib/completion/git-completion.tcsh\n\ndiff --git a/contrib/completion/git-completion.bash\nb/contrib/completion/git-completion.bash\nindex be800e0..6d4b57a 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1,4 +1,6 @@\n-#!bash\n+#!/bin/bash\n+# The above line is important as this script can be executed when used\n+# with another shell such as tcsh\n #\n # bash/zsh completion support for core Git.\n #\n@@ -2481,3 +2483,52 @@ __git_complete gitk __gitk_main\n if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n __git_complete git.exe __git_main\n fi\n+\n+# Method that will output the result of the completion done by\n+# the bash completion script, so that it can be re-used in another\n+# context than the bash complete command.\n+# It accepts 1 to 2 arguments:\n+# 1: The command-line to complete\n+# 2: The index of the word within argument #1 in which the cursor is\n+#    located (optional). If parameter 2 is not provided, it will be\n+#    determined as best possible using parameter 1.\n+_git_complete_with_output ()\n+{\n+       # Set COMP_WORDS to the command-line as bash would.\n+       COMP_WORDS=($1)\n+\n+       # Set COMP_CWORD to the cursor location as bash would.\n+       if [ -n \"$2\" ]; then\n+               COMP_CWORD=$2\n+       else\n+               # Assume the cursor is at the end of parameter #1.\n+               # We must check for a space as the last character which will\n+               # tell us that the previous word is complete and the cursor\n+               # is on the next word.\n+               if [ \"${1: -1}\" == \" \" ]; then\n+                       # The last character is a space, so our\nlocation is at the end\n+                       # of the command-line array\n+                       COMP_CWORD=${#COMP_WORDS[@]}\n+               else\n+                       # The last character is not a space, so our\nlocation is on the\n+                       # last word of the command-line array, so we\nmust decrement the\n+                       # count by 1\n+                       COMP_CWORD=$((${#COMP_WORDS[@]}-1))\n+               fi\n+       fi\n+\n+       # Call _git() or _gitk() of the bash script, based on the first\n+       # element of the command-line\n+       _${COMP_WORDS[0]}\n+\n+       # Print the result that is stored in the bash variable ${COMPREPLY}\n+       for i in ${COMPREPLY[@]}; do\n+               echo \"$i\"\n+       done\n+}\n+\n+if [ -n \"$1\" ] ; then\n+  # If there is an argument, we know the script is being executed\n+  # so go ahead and run the _git_complete_with_output function\n+  _git_complete_with_output \"$1\" \"$2\"\n+fi\ndiff --git a/contrib/completion/git-completion.tcsh\nb/contrib/completion/git-completion.tcsh\nnew file mode 100755\nindex 0000000..7b7baea\n--- /dev/null\n+++ b/contrib/completion/git-completion.tcsh\n@@ -0,0 +1,34 @@\n+#!tcsh\n+#\n+# tcsh completion support for core Git.\n+#\n+# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# This script makes use of the git-completion.bash script to\n+# determine the proper completion for git commands under tcsh.\n+#\n+# To use this completion script:\n+#\n+#    1) Copy both this file and the bash completion script to your\n${HOME} directory\n+#       using the names ${HOME}/.git-completion.tcsh and\n${HOME}/.git-completion.bash.\n+#    2) Add the following line to your .tcshrc/.cshrc:\n+#        source ${HOME}/.git-completion.tcsh\n+\n+# One can change the below line to use a different location\n+set __git_tcsh_completion_script = ${HOME}/.git-completion.bash\n+\n+# Check that the user put the script in the right place\n+if ( ! -e ${__git_tcsh_completion_script} ) then\n+       echo \"ERROR in git-completion.tcsh script.  Cannot find:\n${__git_tcsh_completion_script}.  Git completion will not work.\"\n+       exit\n+endif\n+\n+# Make the script executable if it is not\n+if ( ! -x ${__git_tcsh_completion_script} ) then\n+       chmod u+x ${__git_tcsh_completion_script}\n+endif\n+\n+complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n| sort | uniq`/'\n+complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n| sort | uniq`/'\n+\n--\n1.7.0.4\n"},{"id":"203071","messageId":"20121113111448.GA3817@goldbirke","threadId":"32092","inReplyTo":"CAFj1UpFd9X8Jq5o7B4m35i=merBDvOo4NOtwth=UnG2S5X_rGw@mail.gmail.com","subject":"Re: Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-13T11:14:48Z","receivedAt":"2012-11-13T11:14:48Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Mon, Nov 12, 2012 at 03:07:46PM -0500, Marc Khouzam wrote:\n> Hi,\n\n[...]\n\n> Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n\n[...]\n\n> Thanks\n> \n> Marc\n> \n> ---\n>  contrib/completion/git-completion.bash |   53 +++++++++++++++++++++++++++++++-\n>  contrib/completion/git-completion.tcsh |   34 ++++++++++++++++++++\n>  2 files changed, 86 insertions(+), 1 deletions(-)\n>  create mode 100755 contrib/completion/git-completion.tcsh\n\nPlease have a look at Documentation/SubmittingPatches to see how to\nproperly format the commit message, i.e. no greeting and sign-off in\nthe commit message part, and the S-o-b line should be the last before\nthe '---'.\n\nYour patch seems to be severely line-wrapped.  That document also\ncontains a few MUA-specific tips to help avoid that.\n\nOther than that, it's a good description of the changes and\nconsiderations.  I agree that this approach seems to be the best from\nthe three.\n\n> diff --git a/contrib/completion/git-completion.bash\n> b/contrib/completion/git-completion.bash\n> index be800e0..6d4b57a 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1,4 +1,6 @@\n> -#!bash\n> +#!/bin/bash\n> +# The above line is important as this script can be executed when used\n> +# with another shell such as tcsh\n\nSee comment near the end.\n\n>  #\n>  # bash/zsh completion support for core Git.\n>  #\n> @@ -2481,3 +2483,52 @@ __git_complete gitk __gitk_main\n>  if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n>  __git_complete git.exe __git_main\n>  fi\n> +\n> +# Method that will output the result of the completion done by\n> +# the bash completion script, so that it can be re-used in another\n> +# context than the bash complete command.\n> +# It accepts 1 to 2 arguments:\n> +# 1: The command-line to complete\n> +# 2: The index of the word within argument #1 in which the cursor is\n> +#    located (optional). If parameter 2 is not provided, it will be\n> +#    determined as best possible using parameter 1.\n> +_git_complete_with_output ()\n> +{\n> +       # Set COMP_WORDS to the command-line as bash would.\n> +       COMP_WORDS=($1)\n\nThat comment is only true for older Bash versions.  Since v4 Bash\nsplits the command line at characters that the readline library treats\nas word separators when performing word completion.  But the\ncompletion script has functions to deal with both, so this shouldn't\nbe a problem.\n\n> +\n> +       # Set COMP_CWORD to the cursor location as bash would.\n> +       if [ -n \"$2\" ]; then\n> +               COMP_CWORD=$2\n> +       else\n> +               # Assume the cursor is at the end of parameter #1.\n> +               # We must check for a space as the last character which will\n> +               # tell us that the previous word is complete and the cursor\n> +               # is on the next word.\n> +               if [ \"${1: -1}\" == \" \" ]; then\n> +                       # The last character is a space, so our\n> location is at the end\n> +                       # of the command-line array\n> +                       COMP_CWORD=${#COMP_WORDS[@]}\n> +               else\n> +                       # The last character is not a space, so our\n> location is on the\n> +                       # last word of the command-line array, so we\n> must decrement the\n> +                       # count by 1\n> +                       COMP_CWORD=$((${#COMP_WORDS[@]}-1))\n> +               fi\n> +       fi\n> +\n> +       # Call _git() or _gitk() of the bash script, based on the first\n> +       # element of the command-line\n> +       _${COMP_WORDS[0]}\n> +\n> +       # Print the result that is stored in the bash variable ${COMPREPLY}\n\nReally? ;)\n\nI like the above comments about setting COMP_CWORD, because they\nexplain why you do what you do, which would be otherwise difficult to\nfigure out.  But telling that an echo in a for loop over an array\nprints that array is, well, probably not necessary.\n\n> +       for i in ${COMPREPLY[@]}; do\n> +               echo \"$i\"\n> +       done\n\nThere is no need for the loop here to print the array one element per\nline:\n\n        local IFS=$'\\n'\n        echo \"${COMPREPLY[*]}\"\n\n> +}\n> +\n> +if [ -n \"$1\" ] ; then\n> +  # If there is an argument, we know the script is being executed\n> +  # so go ahead and run the _git_complete_with_output function\n> +  _git_complete_with_output \"$1\" \"$2\"\n\nWhere does the second argument come from?  Below you run this script\nas '${__git_tcsh_completion_script} \"${COMMAND_LINE}\"', i.e. $2 is\nnever set.  Am I missing something?\n\n> +fi\n> diff --git a/contrib/completion/git-completion.tcsh\n> b/contrib/completion/git-completion.tcsh\n> new file mode 100755\n> index 0000000..7b7baea\n> --- /dev/null\n> +++ b/contrib/completion/git-completion.tcsh\n> @@ -0,0 +1,34 @@\n> +#!tcsh\n> +#\n> +# tcsh completion support for core Git.\n> +#\n> +# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n> +# Distributed under the GNU General Public License, version 2.0.\n> +#\n> +# This script makes use of the git-completion.bash script to\n> +# determine the proper completion for git commands under tcsh.\n> +#\n> +# To use this completion script:\n> +#\n> +#    1) Copy both this file and the bash completion script to your\n> ${HOME} directory\n> +#       using the names ${HOME}/.git-completion.tcsh and\n> ${HOME}/.git-completion.bash.\n> +#    2) Add the following line to your .tcshrc/.cshrc:\n> +#        source ${HOME}/.git-completion.tcsh\n> +\n> +# One can change the below line to use a different location\n> +set __git_tcsh_completion_script = ${HOME}/.git-completion.bash\n> +\n> +# Check that the user put the script in the right place\n> +if ( ! -e ${__git_tcsh_completion_script} ) then\n> +       echo \"ERROR in git-completion.tcsh script.  Cannot find:\n> ${__git_tcsh_completion_script}.  Git completion will not work.\"\n> +       exit\n> +endif\n> +\n> +# Make the script executable if it is not\n> +if ( ! -x ${__git_tcsh_completion_script} ) then\n> +       chmod u+x ${__git_tcsh_completion_script}\n> +endif\n\nNot sure about this.  If I source a script to provide completion for a\ncommand, then I definitely don't expect it to change file permissions.\n\nHowever, even if the git completion script is not executable, you can\nstill run it with 'bash ${__git_tcsh_completion_script}'.  This way\nneither the user would need to set permissions, not the script would\nneed to set it behind the users back.  Furthermore, this would also\nmake changing the shebang line unnecessary.\n\n> +\n> +complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n> | sort | uniq`/'\n> +complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n> | sort | uniq`/'\n\nIs the 'sort | uniq' really necessary?  After the completion function\nreturns Bash automatically sorts the elements in COMPREPLY and removes\nany duplicates.  Doesn't tcsh do the same?  I have no idea about tcsh\ncompletion.\n\nDoes the git completion script returns any duplicates at all?\nAmbigious refs come to mind, but I just checked that refs completion,\nor rather 'git for-each-ref' (the command driving refs completion), is\nkind enough to make any ambigious ref names unique (i.e. a branch and\na tag with the same name is listed as 'heads/name' and 'tags/name').\n\n\nThanks,\nGábor\n"},{"id":"203127","messageId":"CAMP44s3imos4DksroRkZ3K6una5H916gvtqttJQna8yGG8XhsQ@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpFd9X8Jq5o7B4m35i=merBDvOo4NOtwth=UnG2S5X_rGw@mail.gmail.com","subject":"Re: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-13T18:31:45Z","receivedAt":"2012-11-13T18:31:45Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Mon, Nov 12, 2012 at 9:07 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n\n> this patch allows tcsh-users to get the benefits of the awesome\n> git-completion.bash script.  It could also help other shells do the same.\n\nMaybe you can try to take a look at the same for zsh:\nhttp://article.gmane.org/gmane.comp.version-control.git/208173\n\n> ---\n>  contrib/completion/git-completion.bash |   53 +++++++++++++++++++++++++++++++-\n>  contrib/completion/git-completion.tcsh |   34 ++++++++++++++++++++\n>  2 files changed, 86 insertions(+), 1 deletions(-)\n>  create mode 100755 contrib/completion/git-completion.tcsh\n>\n> diff --git a/contrib/completion/git-completion.bash\n> b/contrib/completion/git-completion.bash\n> index be800e0..6d4b57a 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1,4 +1,6 @@\n> -#!bash\n> +#!/bin/bash\n> +# The above line is important as this script can be executed when used\n> +# with another shell such as tcsh\n>  #\n>  # bash/zsh completion support for core Git.\n>  #\n> @@ -2481,3 +2483,52 @@ __git_complete gitk __gitk_main\n>  if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n>  __git_complete git.exe __git_main\n>  fi\n> +\n> +# Method that will output the result of the completion done by\n> +# the bash completion script, so that it can be re-used in another\n> +# context than the bash complete command.\n> +# It accepts 1 to 2 arguments:\n> +# 1: The command-line to complete\n> +# 2: The index of the word within argument #1 in which the cursor is\n> +#    located (optional). If parameter 2 is not provided, it will be\n> +#    determined as best possible using parameter 1.\n> +_git_complete_with_output ()\n> +{\n> +       # Set COMP_WORDS to the command-line as bash would.\n> +       COMP_WORDS=($1)\n> +\n> +       # Set COMP_CWORD to the cursor location as bash would.\n> +       if [ -n \"$2\" ]; then\n> +               COMP_CWORD=$2\n> +       else\n> +               # Assume the cursor is at the end of parameter #1.\n> +               # We must check for a space as the last character which will\n> +               # tell us that the previous word is complete and the cursor\n> +               # is on the next word.\n> +               if [ \"${1: -1}\" == \" \" ]; then\n> +                       # The last character is a space, so our\n> location is at the end\n> +                       # of the command-line array\n> +                       COMP_CWORD=${#COMP_WORDS[@]}\n> +               else\n> +                       # The last character is not a space, so our\n> location is on the\n> +                       # last word of the command-line array, so we\n> must decrement the\n> +                       # count by 1\n> +                       COMP_CWORD=$((${#COMP_WORDS[@]}-1))\n> +               fi\n> +       fi\n> +\n> +       # Call _git() or _gitk() of the bash script, based on the first\n> +       # element of the command-line\n> +       _${COMP_WORDS[0]}\n\nYou might want to use __${COMP_WORDS[0]}_main instead.\n\n> +\n> +       # Print the result that is stored in the bash variable ${COMPREPLY}\n> +       for i in ${COMPREPLY[@]}; do\n> +               echo \"$i\"\n> +       done\n> +}\n> +\n> +if [ -n \"$1\" ] ; then\n> +  # If there is an argument, we know the script is being executed\n> +  # so go ahead and run the _git_complete_with_output function\n> +  _git_complete_with_output \"$1\" \"$2\"\n> +fi\n\nWhy do you need this function in this file? You can very easily add\nthis function to git-completion.tcsh.\n\n> diff --git a/contrib/completion/git-completion.tcsh\n> b/contrib/completion/git-completion.tcsh\n> new file mode 100755\n> index 0000000..7b7baea\n> --- /dev/null\n> +++ b/contrib/completion/git-completion.tcsh\n> @@ -0,0 +1,34 @@\n> +#!tcsh\n> +#\n> +# tcsh completion support for core Git.\n> +#\n> +# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n> +# Distributed under the GNU General Public License, version 2.0.\n> +#\n> +# This script makes use of the git-completion.bash script to\n> +# determine the proper completion for git commands under tcsh.\n> +#\n> +# To use this completion script:\n> +#\n> +#    1) Copy both this file and the bash completion script to your\n> ${HOME} directory\n> +#       using the names ${HOME}/.git-completion.tcsh and\n> ${HOME}/.git-completion.bash.\n> +#    2) Add the following line to your .tcshrc/.cshrc:\n> +#        source ${HOME}/.git-completion.tcsh\n> +\n> +# One can change the below line to use a different location\n> +set __git_tcsh_completion_script = ${HOME}/.git-completion.bash\n> +\n> +# Check that the user put the script in the right place\n> +if ( ! -e ${__git_tcsh_completion_script} ) then\n> +       echo \"ERROR in git-completion.tcsh script.  Cannot find:\n> ${__git_tcsh_completion_script}.  Git completion will not work.\"\n> +       exit\n> +endif\n> +\n> +# Make the script executable if it is not\n> +if ( ! -x ${__git_tcsh_completion_script} ) then\n> +       chmod u+x ${__git_tcsh_completion_script}\n> +endif\n\nWhy not just source it?\n\n> +complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n> | sort | uniq`/'\n> +complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n> | sort | uniq`/'\n\nThis seems to be very different from bash's 'complete'. I wonder if\nthe 'complete' commands in the original script cause any problems.\nMaybe only if you source it, but then again, I would expect a warning\nor something when you run it.\n\nBut you can use the trick I did with zsh so you can source it:\n\ncomplete ()\n{\n\t# do nothing\n\treturn 0\n}\n\n. \"$script\"\n\nIt looks like in your case you would need to save the old complete()\nfunction though, or somehow restore it. If you go for this method, you\nuse the __*_main functions though.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203140","messageId":"CAFj1UpGxx_9GHSnJRpe8hDGB6OTio1mcN71LKcR0pxhSVx2xDw@mail.gmail.com","threadId":"32092","inReplyTo":"20121113111448.GA3817@goldbirke","subject":"Re: Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-13T20:12:44Z","receivedAt":"2012-11-13T20:12:44Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"Thanks for the review.\n\nOn Tue, Nov 13, 2012 at 6:14 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> Hi,\n>\n> On Mon, Nov 12, 2012 at 03:07:46PM -0500, Marc Khouzam wrote:\n>> Hi,\n>\n> [...]\n>\n>> Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n>\n> [...]\n>\n>> Thanks\n>>\n>> Marc\n>>\n>> ---\n>>  contrib/completion/git-completion.bash |   53 +++++++++++++++++++++++++++++++-\n>>  contrib/completion/git-completion.tcsh |   34 ++++++++++++++++++++\n>>  2 files changed, 86 insertions(+), 1 deletions(-)\n>>  create mode 100755 contrib/completion/git-completion.tcsh\n>\n> Please have a look at Documentation/SubmittingPatches to see how to\n> properly format the commit message, i.e. no greeting and sign-off in\n> the commit message part, and the S-o-b line should be the last before\n> the '---'.\n\nSorry about that, since I should have noticed it in the doc.\nI will do my best to address all submission issues mentioned\nwhen I post the next version of the patch.\n\n> Your patch seems to be severely line-wrapped.  That document also\n> contains a few MUA-specific tips to help avoid that.\n>\n> Other than that, it's a good description of the changes and\n> considerations.  I agree that this approach seems to be the best from\n> the three.\n>\n>> diff --git a/contrib/completion/git-completion.bash\n>> b/contrib/completion/git-completion.bash\n>> index be800e0..6d4b57a 100644\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -1,4 +1,6 @@\n>> -#!bash\n>> +#!/bin/bash\n>> +# The above line is important as this script can be executed when used\n>> +# with another shell such as tcsh\n>\n> See comment near the end.\n\nGreat suggestion below.  I removed the above change.\n\n>> +       # Set COMP_WORDS to the command-line as bash would.\n>> +       COMP_WORDS=($1)\n>\n> That comment is only true for older Bash versions.  Since v4 Bash\n> splits the command line at characters that the readline library treats\n> as word separators when performing word completion.  But the\n> completion script has functions to deal with both, so this shouldn't\n> be a problem.\n\nI've updated the comment to be more general and left the code\nthe same since it is supported by the script.\n\n>\n>> +       # Print the result that is stored in the bash variable ${COMPREPLY}\n>\n> Really? ;)\n\nRemoved :)\n\n>> +       for i in ${COMPREPLY[@]}; do\n>> +               echo \"$i\"\n>> +       done\n>\n> There is no need for the loop here to print the array one element per\n> line:\n>\n>         local IFS=$'\\n'\n>         echo \"${COMPREPLY[*]}\"\n\nBetter.  Thanks.\n\n>> +if [ -n \"$1\" ] ; then\n>> +  # If there is an argument, we know the script is being executed\n>> +  # so go ahead and run the _git_complete_with_output function\n>> +  _git_complete_with_output \"$1\" \"$2\"\n>\n> Where does the second argument come from?  Below you run this script\n> as '${__git_tcsh_completion_script} \"${COMMAND_LINE}\"', i.e. $2 is\n> never set.  Am I missing something?\n\nThis second argument is optional and, if present, will be put in\n$COMP_CWORD.  If not present, $COMP_CWORD must be computed\nfrom $1.  Also see comment above _git_complete_with_output ().\ntcsh does not provide me with this information, so I cannot make use of it.\nHowever, I thought it would be more future-proof to allow it for other shells\nwhich may have that information.\n\nIt is not necessary for tcsh, so I can remove if you prefer?\n\n>> +# Make the script executable if it is not\n>> +if ( ! -x ${__git_tcsh_completion_script} ) then\n>> +       chmod u+x ${__git_tcsh_completion_script}\n>> +endif\n>\n> Not sure about this.  If I source a script to provide completion for a\n> command, then I definitely don't expect it to change file permissions.\n>\n> However, even if the git completion script is not executable, you can\n> still run it with 'bash ${__git_tcsh_completion_script}'.  This way\n> neither the user would need to set permissions, not the script would\n> need to set it behind the users back.  Furthermore, this would also\n> make changing the shebang line unnecessary.\n\nVery nice!  Done.\n\n>> +complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n>> | sort | uniq`/'\n>> +complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n>> | sort | uniq`/'\n>\n> Is the 'sort | uniq' really necessary?  After the completion function\n> returns Bash automatically sorts the elements in COMPREPLY and removes\n> any duplicates.  Doesn't tcsh do the same?  I have no idea about tcsh\n> completion.\n\nOn my machine, tcsh does not remove duplicates.  It does sort the results\nbut that is done after I've run 'uniq', which is too late.  I'm not\nhappy about this\neither, but the other option is to improve git-completion.bash to\navoid duplicates,\nwhich seemed less justified.\n\n> Does the git completion script returns any duplicates at all?\n\nIt does.  'help' is returned twice for example.\nAlso, when completing 'git checkout ' in the git repo, I can see multiple\n'todo' branches, as well as 'master', 'pu', 'next', etc.\n\nYou can actually try it without tcsh by running my proposed version of\ngit-completion.bash like this:\n\ncd git/contrib/completion\nbash git-completion.bash \"git checkout \" | sort | uniq --repeated\n\n> Ambigious refs come to mind, but I just checked that refs completion,\n> or rather 'git for-each-ref' (the command driving refs completion), is\n> kind enough to make any ambigious ref names unique (i.e. a branch and\n> a tag with the same name is listed as 'heads/name' and 'tags/name').\n\nI will post a new version of the patch after looking at Felipe's patch for zsh,\nwhich I was not aware of.\n\nThanks!\n\nMarc\n"},{"id":"203160","messageId":"20121113234636.GS12052@goldbirke","threadId":"32092","inReplyTo":"CAFj1UpGxx_9GHSnJRpe8hDGB6OTio1mcN71LKcR0pxhSVx2xDw@mail.gmail.com","subject":"Re: Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-13T23:46:36Z","receivedAt":"2012-11-13T23:46:36Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Tue, Nov 13, 2012 at 03:12:44PM -0500, Marc Khouzam wrote:\n> >> +if [ -n \"$1\" ] ; then\n> >> +  # If there is an argument, we know the script is being executed\n> >> +  # so go ahead and run the _git_complete_with_output function\n> >> +  _git_complete_with_output \"$1\" \"$2\"\n> >\n> > Where does the second argument come from?  Below you run this script\n> > as '${__git_tcsh_completion_script} \"${COMMAND_LINE}\"', i.e. $2 is\n> > never set.  Am I missing something?\n> \n> This second argument is optional and, if present, will be put in\n> $COMP_CWORD.  If not present, $COMP_CWORD must be computed\n> from $1.  Also see comment above _git_complete_with_output ().\n> tcsh does not provide me with this information, so I cannot make use of it.\n> However, I thought it would be more future-proof to allow it for other shells\n> which may have that information.\n> \n> It is not necessary for tcsh, so I can remove if you prefer?\n\nI see.  I read those comments and understood what it is about.  I was\njust surprised that the code is there to make use of it, yet it's not\nspecified when invoking that function.\n\nSince it's a trivial piece of code, I would say let's keep it.  Could\nyou please add a sentence about it (that it's for possible future\nusers and it's not used at the moment) to the commit message for\nfuture reference?\n\n> >> +complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n> >> | sort | uniq`/'\n> >> +complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n> >> | sort | uniq`/'\n> >\n> > Is the 'sort | uniq' really necessary?  After the completion function\n> > returns Bash automatically sorts the elements in COMPREPLY and removes\n> > any duplicates.  Doesn't tcsh do the same?  I have no idea about tcsh\n> > completion.\n> \n> On my machine, tcsh does not remove duplicates.  It does sort the results\n> but that is done after I've run 'uniq', which is too late.  I'm not\n> happy about this\n> either, but the other option is to improve git-completion.bash to\n> avoid duplicates,\n> which seemed less justified.\n\nOk.  Then keep it for the time being, and we'll see what we can do to\navoid those duplicates.\n\n> > Does the git completion script returns any duplicates at all?\n> \n> It does.  'help' is returned twice for example.\n\nRight.  Now that you mentioned it, I remember I noticed it a while\nago, too.  I even wrote a patch to fix it, but not sure what became of\nit.  Will try to dig it up.\n\n> Also, when completing 'git checkout ' in the git repo, I can see multiple\n> 'todo' branches, as well as 'master', 'pu', 'next', etc.\n> \n> You can actually try it without tcsh by running my proposed version of\n> git-completion.bash like this:\n> \n> cd git/contrib/completion\n> bash git-completion.bash \"git checkout \" | sort | uniq --repeated\n\nInteresting, I can't reproduce.  Are the duplicates also there, if you\nstart a bash, source git-completion.bash, and run __git_refs ?\n"},{"id":"203163","messageId":"20121114000909.GA14953@goldbirke","threadId":"32092","inReplyTo":"CAFj1UpFd9X8Jq5o7B4m35i=merBDvOo4NOtwth=UnG2S5X_rGw@mail.gmail.com","subject":"Re: Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-14T00:09:09Z","receivedAt":"2012-11-14T00:09:09Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nI've got two more comments.\n\nOn Mon, Nov 12, 2012 at 03:07:46PM -0500, Marc Khouzam wrote:\n> @@ -2481,3 +2483,52 @@ __git_complete gitk __gitk_main\n>  if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n>  __git_complete git.exe __git_main\n>  fi\n> +\n> +# Method that will output the result of the completion done by\n> +# the bash completion script, so that it can be re-used in another\n> +# context than the bash complete command.\n> +# It accepts 1 to 2 arguments:\n> +# 1: The command-line to complete\n> +# 2: The index of the word within argument #1 in which the cursor is\n> +#    located (optional). If parameter 2 is not provided, it will be\n> +#    determined as best possible using parameter 1.\n> +_git_complete_with_output ()\n\nWe differentiate between _git_whatever() and __git_whatever()\nfunctions.  The former performs completion for the 'whatever' git\ncommand/alias, the latter is a completion helper function.  This\nis a helper function, so it should begin with double underscores.\n\n> +{\n> +       # Set COMP_WORDS to the command-line as bash would.\n> +       COMP_WORDS=($1)\n> +\n> +       # Set COMP_CWORD to the cursor location as bash would.\n> +       if [ -n \"$2\" ]; then\n\nA while ago the completion script was made 'set -u'-clean.  (If 'set\n-u' is enabled, then it's an error to access undefined variables).\nI'm not sure how many people are out there who'd use this script for\ntcsh while having 'set -u' in their profile...  probably not that\nmany.  Still, I think it would be great to keep it up.\n\nHere $2 would be undefined, so accessingit it would cause an error\nunder those semantincs.  Please use ${2-} instead (use empty string\nwhen undefined).\n\n> +if [ -n \"$1\" ] ; then\n\nSame here.\n\n> +  # If there is an argument, we know the script is being executed\n> +  # so go ahead and run the _git_complete_with_output function\n> +  _git_complete_with_output \"$1\" \"$2\"\n\nAnd here.\n\nThanks\nGábor\n"},{"id":"203164","messageId":"20121114001159.GA14631@goldbirke","threadId":"32092","inReplyTo":"CAMP44s3imos4DksroRkZ3K6una5H916gvtqttJQna8yGG8XhsQ@mail.gmail.com","subject":"Re: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-14T00:11:59Z","receivedAt":"2012-11-14T00:11:59Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Tue, Nov 13, 2012 at 07:31:45PM +0100, Felipe Contreras wrote:\n> On Mon, Nov 12, 2012 at 9:07 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n> > +       # Call _git() or _gitk() of the bash script, based on the first\n> > +       # element of the command-line\n> > +       _${COMP_WORDS[0]}\n> \n> You might want to use __${COMP_WORDS[0]}_main instead.\n\nThat wouldn't work.  __git_main() doesn't set up the\ncommand-line-specific variables, but the wrapper around it does.\n\n\n> > +# Make the script executable if it is not\n> > +if ( ! -x ${__git_tcsh_completion_script} ) then\n> > +       chmod u+x ${__git_tcsh_completion_script}\n> > +endif\n> \n> Why not just source it?\n\nThe goal is to re-use a Bash script to do completion in tcsh.  They\nare two different breeds, tcsh doesn't grok bash.  So sourcing the\ncompletion script is not an option, but we can still run it via Bash\nand use it's results.\n"},{"id":"203165","messageId":"20121114004930.GT12052@goldbirke","threadId":"32092","inReplyTo":"20121113234636.GS12052@goldbirke","subject":"[PATCH] completion: remove 'help' duplicate from porcelain commands","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-14T00:49:30Z","receivedAt":"2012-11-14T00:49:30Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"The list of all git commands is computed from the output of 'git help\n-a', which already includes 'help', so there is no need to explicitly\nadd it once more when computing the list of porcelain commands.\n\nNote that 'help' wasn't actually offered twice because of this,\nbecause Bash filters duplicates from possible completion words.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n\n> > > Does the git completion script returns any duplicates at all?\n> > \n> > It does.  'help' is returned twice for example.\n> \n> Right.  Now that you mentioned it, I remember I noticed it a while\n> ago, too.  I even wrote a patch to fix it, but not sure what became of\n> it.  Will try to dig it up.\n\nHere it is.  It turns out I wrote it in May this year, but according to\ngmane and my mailbox never sent it out.\n\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex bc0657a2..b7b1a834 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -585,7 +585,7 @@ __git_list_porcelain_commands ()\n {\n \tlocal i IFS=\" \"$'\\n'\n \t__git_compute_all_commands\n-\tfor i in \"help\" $__git_all_commands\n+\tfor i in $__git_all_commands\n \tdo\n \t\tcase $i in\n \t\t*--*)             : helper pattern;;\n-- \n1.8.0.128.g441b4b3\n"},{"id":"203168","messageId":"CAFj1UpEB5TqQKmEDoPY-nH5d+Ki_0R70Jd=WXtkxEj-emHEfaA@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s3imos4DksroRkZ3K6una5H916gvtqttJQna8yGG8XhsQ@mail.gmail.com","subject":"Re: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-14T03:36:24Z","receivedAt":"2012-11-14T03:36:24Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"Thanks for the review.  I wasn't aware that you were doing\na similar effort for zsh.\n\nOn Tue, Nov 13, 2012 at 1:31 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Mon, Nov 12, 2012 at 9:07 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>\n>> this patch allows tcsh-users to get the benefits of the awesome\n>> git-completion.bash script.  It could also help other shells do the same.\n>\n> Maybe you can try to take a look at the same for zsh:\n> http://article.gmane.org/gmane.comp.version-control.git/208173\n\nCool.  The major difference is that (as Gábor mentioned) zsh understands bash\nsyntax but tcsh does not.  tcsh doesn't even allow to define\nfunctions.  So we have\nto take a different approach to get the bash completion script to be\nused by tcsh.\n\n>> ---\n>>  contrib/completion/git-completion.bash |   53 +++++++++++++++++++++++++++++++-\n>>  contrib/completion/git-completion.tcsh |   34 ++++++++++++++++++++\n>>  2 files changed, 86 insertions(+), 1 deletions(-)\n>>  create mode 100755 contrib/completion/git-completion.tcsh\n>>\n>> diff --git a/contrib/completion/git-completion.bash\n>> b/contrib/completion/git-completion.bash\n>> index be800e0..6d4b57a 100644\n>> --- a/contrib/completion/git-completion.bash\n>> +++ b/contrib/completion/git-completion.bash\n>> @@ -1,4 +1,6 @@\n>> -#!bash\n>> +#!/bin/bash\n>> +# The above line is important as this script can be executed when used\n>> +# with another shell such as tcsh\n>>  #\n>>  # bash/zsh completion support for core Git.\n>>  #\n>> @@ -2481,3 +2483,52 @@ __git_complete gitk __gitk_main\n>>  if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n>>  __git_complete git.exe __git_main\n>>  fi\n>> +\n>> +# Method that will output the result of the completion done by\n>> +# the bash completion script, so that it can be re-used in another\n>> +# context than the bash complete command.\n>> +# It accepts 1 to 2 arguments:\n>> +# 1: The command-line to complete\n>> +# 2: The index of the word within argument #1 in which the cursor is\n>> +#    located (optional). If parameter 2 is not provided, it will be\n>> +#    determined as best possible using parameter 1.\n>> +_git_complete_with_output ()\n>> +{\n>> +       # Set COMP_WORDS to the command-line as bash would.\n>> +       COMP_WORDS=($1)\n>> +\n>> +       # Set COMP_CWORD to the cursor location as bash would.\n>> +       if [ -n \"$2\" ]; then\n>> +               COMP_CWORD=$2\n>> +       else\n>> +               # Assume the cursor is at the end of parameter #1.\n>> +               # We must check for a space as the last character which will\n>> +               # tell us that the previous word is complete and the cursor\n>> +               # is on the next word.\n>> +               if [ \"${1: -1}\" == \" \" ]; then\n>> +                       # The last character is a space, so our\n>> location is at the end\n>> +                       # of the command-line array\n>> +                       COMP_CWORD=${#COMP_WORDS[@]}\n>> +               else\n>> +                       # The last character is not a space, so our\n>> location is on the\n>> +                       # last word of the command-line array, so we\n>> must decrement the\n>> +                       # count by 1\n>> +                       COMP_CWORD=$((${#COMP_WORDS[@]}-1))\n>> +               fi\n>> +       fi\n>> +\n>> +       # Call _git() or _gitk() of the bash script, based on the first\n>> +       # element of the command-line\n>> +       _${COMP_WORDS[0]}\n>\n> You might want to use __${COMP_WORDS[0]}_main instead.\n>\n>> +\n>> +       # Print the result that is stored in the bash variable ${COMPREPLY}\n>> +       for i in ${COMPREPLY[@]}; do\n>> +               echo \"$i\"\n>> +       done\n>> +}\n>> +\n>> +if [ -n \"$1\" ] ; then\n>> +  # If there is an argument, we know the script is being executed\n>> +  # so go ahead and run the _git_complete_with_output function\n>> +  _git_complete_with_output \"$1\" \"$2\"\n>> +fi\n>\n> Why do you need this function in this file? You can very easily add\n> this function to git-completion.tcsh.\n\ntcsh does not allow to define functions, so it is not aware of any\nof the git-completion.bash functions.  So, git-completion.tcsh\ncannot call anything from git-completion.bash.\n\n>> diff --git a/contrib/completion/git-completion.tcsh\n>> b/contrib/completion/git-completion.tcsh\n>> new file mode 100755\n>> index 0000000..7b7baea\n>> --- /dev/null\n>> +++ b/contrib/completion/git-completion.tcsh\n>> @@ -0,0 +1,34 @@\n>> +#!tcsh\n>> +#\n>> +# tcsh completion support for core Git.\n>> +#\n>> +# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n>> +# Distributed under the GNU General Public License, version 2.0.\n>> +#\n>> +# This script makes use of the git-completion.bash script to\n>> +# determine the proper completion for git commands under tcsh.\n>> +#\n>> +# To use this completion script:\n>> +#\n>> +#    1) Copy both this file and the bash completion script to your\n>> ${HOME} directory\n>> +#       using the names ${HOME}/.git-completion.tcsh and\n>> ${HOME}/.git-completion.bash.\n>> +#    2) Add the following line to your .tcshrc/.cshrc:\n>> +#        source ${HOME}/.git-completion.tcsh\n>> +\n>> +# One can change the below line to use a different location\n>> +set __git_tcsh_completion_script = ${HOME}/.git-completion.bash\n>> +\n>> +# Check that the user put the script in the right place\n>> +if ( ! -e ${__git_tcsh_completion_script} ) then\n>> +       echo \"ERROR in git-completion.tcsh script.  Cannot find:\n>> ${__git_tcsh_completion_script}.  Git completion will not work.\"\n>> +       exit\n>> +endif\n>> +\n>> +# Make the script executable if it is not\n>> +if ( ! -x ${__git_tcsh_completion_script} ) then\n>> +       chmod u+x ${__git_tcsh_completion_script}\n>> +endif\n>\n> Why not just source it?\n>\n>> +complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n>> | sort | uniq`/'\n>> +complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n>> | sort | uniq`/'\n>\n> This seems to be very different from bash's 'complete'. I wonder if\n> the 'complete' commands in the original script cause any problems.\n> Maybe only if you source it, but then again, I would expect a warning\n> or something when you run it.\n\nIf you source the script under tcsh it will fail miserably because the bash\nsyntax is very different.  But when you run it, it runs under the bash shell\nso everything will work fine.  The 'complete' command in the bash script\nwill run, but will only affect the temporary bash shell that was started\nto run the script.  Useless but harmless.\n\n> But you can use the trick I did with zsh so you can source it:\n>\n> complete ()\n> {\n>         # do nothing\n>         return 0\n> }\n>\n> . \"$script\"\n\nThis is pretty cool.  Function overriding in shell scripts!  tcsh doesn't\neven have functions, so that trick is out of its league :)\n\nThanks\n\nMarc\n"},{"id":"203169","messageId":"CAFj1UpHgPvdDeKZ-Ap7-aVx6p_pxT4a2F01ajmNa00txPyS=Qw@mail.gmail.com","threadId":"32092","inReplyTo":"20121113234636.GS12052@goldbirke","subject":"Re: Fwd: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-14T04:26:33Z","receivedAt":"2012-11-14T04:26:33Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Tue, Nov 13, 2012 at 6:46 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> Hi,\n>\n> On Tue, Nov 13, 2012 at 03:12:44PM -0500, Marc Khouzam wrote:\n>> >> +if [ -n \"$1\" ] ; then\n>> >> +  # If there is an argument, we know the script is being executed\n>> >> +  # so go ahead and run the _git_complete_with_output function\n>> >> +  _git_complete_with_output \"$1\" \"$2\"\n>> >\n>> > Where does the second argument come from?  Below you run this script\n>> > as '${__git_tcsh_completion_script} \"${COMMAND_LINE}\"', i.e. $2 is\n>> > never set.  Am I missing something?\n>>\n>> This second argument is optional and, if present, will be put in\n>> $COMP_CWORD.  If not present, $COMP_CWORD must be computed\n>> from $1.  Also see comment above _git_complete_with_output ().\n>> tcsh does not provide me with this information, so I cannot make use of it.\n>> However, I thought it would be more future-proof to allow it for other shells\n>> which may have that information.\n>>\n>> It is not necessary for tcsh, so I can remove if you prefer?\n>\n> I see.  I read those comments and understood what it is about.  I was\n> just surprised that the code is there to make use of it, yet it's not\n> specified when invoking that function.\n>\n> Since it's a trivial piece of code, I would say let's keep it.  Could\n> you please add a sentence about it (that it's for possible future\n> users and it's not used at the moment) to the commit message for\n> future reference?\n\nWill do.\n\n>> >> +complete git  'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n>> >> | sort | uniq`/'\n>> >> +complete gitk 'p/*/`${__git_tcsh_completion_script} \"${COMMAND_LINE}\"\n>> >> | sort | uniq`/'\n>> >\n>> > Is the 'sort | uniq' really necessary?  After the completion function\n>> > returns Bash automatically sorts the elements in COMPREPLY and removes\n>> > any duplicates.  Doesn't tcsh do the same?  I have no idea about tcsh\n>> > completion.\n>>\n>> On my machine, tcsh does not remove duplicates.  It does sort the results\n>> but that is done after I've run 'uniq', which is too late.  I'm not\n>> happy about this\n>> either, but the other option is to improve git-completion.bash to\n>> avoid duplicates,\n>> which seemed less justified.\n>\n> Ok.  Then keep it for the time being, and we'll see what we can do to\n> avoid those duplicates.\n\nThanks.\n\n>> > Does the git completion script returns any duplicates at all?\n>>\n>> It does.  'help' is returned twice for example.\n>\n> Right.  Now that you mentioned it, I remember I noticed it a while\n> ago, too.  I even wrote a patch to fix it, but not sure what became of\n> it.  Will try to dig it up.\n\nThanks for already posting the patch.\n\n>> Also, when completing 'git checkout ' in the git repo, I can see multiple\n>> 'todo' branches, as well as 'master', 'pu', 'next', etc.\n>>\n>> You can actually try it without tcsh by running my proposed version of\n>> git-completion.bash like this:\n>>\n>> cd git/contrib/completion\n>> bash git-completion.bash \"git checkout \" | sort | uniq --repeated\n>\n> Interesting, I can't reproduce.  Are the duplicates also there, if you\n> start a bash, source git-completion.bash, and run __git_refs ?\n\nRunning __git_refs does not show the duplicates, but running\n__git refs '' 1\ndoes show them.\nThat second parameter causes __git_refs to\n\"use the guess heuristic employed by checkout for tracking branches\"\n\nI don't quite understand this, but what I can see is that my remote\nbranches GitHub/master and origin/master each cause another\n'master' to be listed:\n\n$ __git_refs '' 1|grep master\nmaster\nGitHub/master\norigin/master\nmaster\nmaster\n\nAll fixes are done and I'll post a second version of the patch\nas soon as I can figure out the formatting properly.\n\nThanks again\n\nMarc\n"},{"id":"203263","messageId":"CAMP44s2Nsxu9CsTxAXiSamjA5SqxwB2qWx72vu8Mit1ruLMWJg@mail.gmail.com","threadId":"32092","inReplyTo":"20121114001159.GA14631@goldbirke","subject":"Re: [PATCH] Add tcsh-completion support to contrib by using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-15T02:40:17Z","receivedAt":"2012-11-15T02:40:17Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Wed, Nov 14, 2012 at 1:11 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> On Tue, Nov 13, 2012 at 07:31:45PM +0100, Felipe Contreras wrote:\n>> On Mon, Nov 12, 2012 at 9:07 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>> > +       # Call _git() or _gitk() of the bash script, based on the first\n>> > +       # element of the command-line\n>> > +       _${COMP_WORDS[0]}\n>>\n>> You might want to use __${COMP_WORDS[0]}_main instead.\n>\n> That wouldn't work.  __git_main() doesn't set up the\n> command-line-specific variables, but the wrapper around it does.\n\nYeah, but you can set those command-line-specific variables manually,\nlike the zsh completion wrapper does.\n\nThe problem with the _git wrapper is that it will call the\nbash-specific complete command.\n\n>> > +# Make the script executable if it is not\n>> > +if ( ! -x ${__git_tcsh_completion_script} ) then\n>> > +       chmod u+x ${__git_tcsh_completion_script}\n>> > +endif\n>>\n>> Why not just source it?\n>\n> The goal is to re-use a Bash script to do completion in tcsh.  They\n> are two different breeds, tcsh doesn't grok bash.  So sourcing the\n> completion script is not an option, but we can still run it via Bash\n> and use it's results.\n\nI see, but the tcsh script can do something like this:\n\nbash <<\\EOF\necho $BASH\n\\EOF\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203285","messageId":"1352980269-15569-1-git-send-email-marc.khouzam@gmail.com","threadId":"32092","inReplyTo":"CAFj1UpHgPvdDeKZ-Ap7-aVx6p_pxT4a2F01ajmNa00txPyS=Qw@mail.gmail.com","subject":"[PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-15T11:51:09Z","receivedAt":"2012-11-15T11:51:09Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"The current tcsh-completion support for Git, as can be found on the\nInternet, takes the approach of defining the possible completions\nexplicitly.  This has the obvious draw-back to require constant\nupdating as the Git code base evolves.\n\nThe approach taken by this commit is to to re-use the advanced bash\ncompletion script and use its result for tcsh completion.  This is\nachieved by executing (versus sourcing) the bash script and\noutputting the completion result for tcsh consumption.\n\nThree solutions were looked at to implement this approach with (A)\nbeing retained:\n\n  A) Modifications:\n          git-completion.bash and new git-completion.tcsh\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash.\n     When being executed, the script will output the result of the\n     computed completion to be re-used elsewhere (e.g., in tcsh).\n\n     The modification to git-completion.bash is made not to be\n     tcsh-specific, but to allow future users to also re-use its\n     output.  Therefore, to be general, git-completion.bash accepts a\n     second optional parameter, which is not used by tcsh, but could\n     prove useful for other users.\n\n     Pros:\n       1- allows the git-completion.bash script to easily be re-used\n       2- tcsh support is mostly isolated in git-completion.tcsh\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n\n  B) Modifications:\n          git-completion.bash\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash,\n     and sourced using tcsh.\n\n     Pros:\n       1- only requires the user to deal with a single file\n       2- maintenance more obvious for tcsh since it is entirely part\n          of the same git-completion.bash script.\n     Cons:\n       1- tcsh support could affect bash support as they share the\n          same script\n       2- small tcsh section must use syntax suitable for both tcsh\n          and bash and must be at the beginning of the script\n       3- requires script to have a fixed name and location:\n          ${HOME}/.git-completion.sh (for tcsh users only)\n\n  C) Modifications:\n          New git-completion.tcsh\n\n     Provide a short tcsh script that converts git-completion.bash\n     into an executable script suitable to be used by tcsh.\n\n     Pros:\n       1- tcsh support is entirely isolated in git-completion.tcsh\n       2- new tcsh script can be as complex as needed\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n       3- sourcing the new script will generate a third script\n\nApproach (A) was selected to keep the tcsh completion support well\nisolated without introducing excessive complexity.\n\nSigned-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n---\n\nHere is the updated version of the patch.\nI got git send-email to work, so I hope the formatting will be correct.\n\nThanks in advance.\n\nMarc\n\n contrib/completion/git-completion.bash |   47 ++++++++++++++++++++++++++++++++\n contrib/completion/git-completion.tcsh |   29 +++++++++++++++++++\n 2 files changed, 76 insertions(+), 0 deletions(-)\n create mode 100644 contrib/completion/git-completion.tcsh\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex be800e0..d71a016 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2481,3 +2481,50 @@ __git_complete gitk __gitk_main\n if [ Cygwin = \"$(uname -o 2>/dev/null)\" ]; then\n __git_complete git.exe __git_main\n fi\n+\n+# Method that will output the result of the completion done by\n+# the bash completion script, so that it can be re-used in another\n+# context than the bash complete command.\n+# It accepts 1 to 2 arguments:\n+# 1: The command-line to complete\n+# 2: The index of the word within argument #1 in which the cursor is\n+#    located (optional). If parameter 2 is not provided, it will be\n+#    determined as best possible using parameter 1.\n+__git_complete_with_output ()\n+{\n+\t# Set COMP_WORDS in a way that can be handled by the bash script.\n+\tCOMP_WORDS=($1)\n+\n+\t# Set COMP_CWORD to the cursor location as bash would.\n+\tif [ -n \"${2-}\" ]; then\n+\t\tCOMP_CWORD=$2\n+\telse\n+\t\t# Assume the cursor is at the end of parameter #1.\n+\t\t# We must check for a space as the last character which will\n+\t\t# tell us that the previous word is complete and the cursor\n+\t\t# is on the next word.\n+\t\tif [ \"${1: -1}\" == \" \" ]; then\n+\t\t\t# The last character is a space, so our location is at the end\n+\t\t\t# of the command-line array\n+\t\t\tCOMP_CWORD=${#COMP_WORDS[@]}\n+\t\telse\n+\t\t\t# The last character is not a space, so our location is on the\n+\t\t\t# last word of the command-line array, so we must decrement the\n+\t\t\t# count by 1\n+\t\t\tCOMP_CWORD=$((${#COMP_WORDS[@]}-1))\n+\t\tfi\n+\tfi\n+\n+\t# Call _git() or _gitk() of the bash script, based on the first\n+\t# element of the command-line\n+\t_${COMP_WORDS[0]}\n+\n+\tlocal IFS=$'\\n'\n+\techo \"${COMPREPLY[*]}\"\n+}\n+\n+if [ -n \"${1-}\" ] ; then\n+  # If there is an argument, we know the script is being executed\n+  # so go ahead and run the _git_complete_with_output function\n+  __git_complete_with_output \"${1-}\" \"${2-}\"\n+fi\ndiff --git a/contrib/completion/git-completion.tcsh b/contrib/completion/git-completion.tcsh\nnew file mode 100644\nindex 0000000..6096ea8\n--- /dev/null\n+++ b/contrib/completion/git-completion.tcsh\n@@ -0,0 +1,29 @@\n+#!tcsh\n+#\n+# tcsh completion support for core Git.\n+#\n+# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# This script makes use of the git-completion.bash script to\n+# determine the proper completion for git commands under tcsh.\n+#\n+# To use this completion script:\n+#\n+#    1) Copy both this file and the bash completion script to your ${HOME} directory\n+#       using the names ${HOME}/.git-completion.tcsh and ${HOME}/.git-completion.bash.\n+#    2) Add the following line to your .tcshrc/.cshrc:\n+#        source ${HOME}/.git-completion.tcsh\n+\n+# One can change the below line to use a different location\n+set __git_tcsh_completion_script = ${HOME}/.git-completion.bash\n+\n+# Check that the user put the script in the right place\n+if ( ! -e ${__git_tcsh_completion_script} ) then\n+\techo \"ERROR in git-completion.tcsh script.  Cannot find: ${__git_tcsh_completion_script}.  Git completion will not work.\"\n+\texit\n+endif\n+\n+complete git  'p/*/`bash ${__git_tcsh_completion_script} \"${COMMAND_LINE}\" | sort | uniq`/'\n+complete gitk 'p/*/`bash ${__git_tcsh_completion_script} \"${COMMAND_LINE}\" | sort | uniq`/'\n+\n-- \n1.7.0.4\n"},{"id":"203323","messageId":"CAMP44s0Guq0nYJEfbvNDyt8Oqaux-cXbTsyro6pxUnEpA4+XOw@mail.gmail.com","threadId":"32092","inReplyTo":"1352980269-15569-1-git-send-email-marc.khouzam@gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T01:41:41Z","receivedAt":"2012-11-16T01:41:41Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Thu, Nov 15, 2012 at 12:51 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n> The current tcsh-completion support for Git, as can be found on the\n> Internet, takes the approach of defining the possible completions\n> explicitly.  This has the obvious draw-back to require constant\n> updating as the Git code base evolves.\n>\n> The approach taken by this commit is to to re-use the advanced bash\n> completion script and use its result for tcsh completion.  This is\n> achieved by executing (versus sourcing) the bash script and\n> outputting the completion result for tcsh consumption.\n>\n> Three solutions were looked at to implement this approach with (A)\n> being retained:\n>\n>   A) Modifications:\n>           git-completion.bash and new git-completion.tcsh\n\nAs I said, I don't think this is needed. It can be done in a single\nstand-alone script without modifications to git-completion.bash.\n\nThis works:\n\nset called = ($_)\nset script = \"${called[2]}.tmp\"\n\ncat <<\\EOF > $script\nsource \"$HOME/.git-completion.sh\"\n\n# Set COMP_WORDS in a way that can be handled by the bash script.\nCOMP_WORDS=($1)\n\n# Set COMP_CWORD to the cursor location as bash would.\nif [ -n \"${2-}\" ]; then\n\tCOMP_CWORD=$2\nelse\n\t# Assume the cursor is at the end of parameter #1.\n\t# We must check for a space as the last character which will\n\t# tell us that the previous word is complete and the cursor\n\t# is on the next word.\n\tif [ \"${1: -1}\" == \" \" ]; then\n\t\t# The last character is a space, so our location is at the end\n\t\t# of the command-line array\n\t\tCOMP_CWORD=${#COMP_WORDS[@]}\n\telse\n\t\t# The last character is not a space, so our location is on the\n\t\t# last word of the command-line array, so we must decrement the\n\t\t# count by 1\n\t\tCOMP_CWORD=$((${#COMP_WORDS[@]}-1))\n\tfi\nfi\n\n# Call _git() or _gitk() of the bash script, based on the first\n# element of the command-line\n_${COMP_WORDS[0]}\n\nIFS=$'\\n'\necho \"${COMPREPLY[*]}\"\n\\EOF\n\ncomplete git  'p/*/`bash ${script} \"${COMMAND_LINE}\" | sort | uniq`/'\ncomplete gitk 'p/*/`bash ${script} \"${COMMAND_LINE}\" | sort | uniq`/'\n\n-- \nFelipe Contreras\n"},{"id":"203343","messageId":"CAFj1UpEdft+L5KW+tMy6Lqm1eUkHQgwWuXaC0UTUdqwW=ohk-Q@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s0Guq0nYJEfbvNDyt8Oqaux-cXbTsyro6pxUnEpA4+XOw@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-16T14:39:45Z","receivedAt":"2012-11-16T14:39:45Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Thu, Nov 15, 2012 at 8:41 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Thu, Nov 15, 2012 at 12:51 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>> The current tcsh-completion support for Git, as can be found on the\n>> Internet, takes the approach of defining the possible completions\n>> explicitly.  This has the obvious draw-back to require constant\n>> updating as the Git code base evolves.\n>>\n>> The approach taken by this commit is to to re-use the advanced bash\n>> completion script and use its result for tcsh completion.  This is\n>> achieved by executing (versus sourcing) the bash script and\n>> outputting the completion result for tcsh consumption.\n>>\n>> Three solutions were looked at to implement this approach with (A)\n>> being retained:\n>>\n>>   A) Modifications:\n>>           git-completion.bash and new git-completion.tcsh\n>\n> As I said, I don't think this is needed. It can be done in a single\n> stand-alone script without modifications to git-completion.bash.\n>\n> This works:\n\nThank you for taking the time to try things out.\n\nWhat you suggest below is an improvement on solution (C).\nI had chosen (A) instead because (C) creates a third script\nwhich gets generated each time a new shell is started.\nIt should be safe, but it felt a little wrong.\nBut I have to admit I was on the fence between the two\nsolutions.\n\nIf you guys don't think it is bad to generate a third script\n(that the user may notice in his ${HOME}),\nI'll post a new patch (and try once more to get gmail not to\nreplace the tabs with spaces), using your improved\nsolution (C).\n\n> set called = ($_)\n\nI fought with this a lot before posting to the list.\nIt seems that $_ is not set when a double sourcing\nhappens.  Testing the solution as an actual user\nshowed me that when I start a new shell it\nsources ~/.tcshrc, which then sources ~/.git-completion.tcsh\nand then $_ is empty for some reason.\n\nI couldn't find another way to figure out where the script\nis located, which is why I had to force the user to use\n${HOME} for everything.\n\n> set script = \"${called[2]}.tmp\"\n>\n> cat <<\\EOF > $script\n> source \"$HOME/.git-completion.sh\"\n\nThis is nice.  Shame on me not to have thought about it.\nIn my version I actually 'cat' the entire bash script into $script\ninstead of simply sourcing it.\n\n> # Set COMP_WORDS in a way that can be handled by the bash script.\n> COMP_WORDS=($1)\n>\n> # Set COMP_CWORD to the cursor location as bash would.\n> if [ -n \"${2-}\" ]; then\n>         COMP_CWORD=$2\n> else\n\nSince this code will be part of a tcsh-only script, I don't think\nwe need to prepare for a possible $2.  tcsh won't provide it.\nSo, I'll remove that logic, which will simplify things slightly.\n\n>         # Assume the cursor is at the end of parameter #1.\n>         # We must check for a space as the last character which will\n>         # tell us that the previous word is complete and the cursor\n>         # is on the next word.\n>         if [ \"${1: -1}\" == \" \" ]; then\n>                 # The last character is a space, so our location is at the end\n>                 # of the command-line array\n>                 COMP_CWORD=${#COMP_WORDS[@]}\n>         else\n>                 # The last character is not a space, so our location is on the\n>                 # last word of the command-line array, so we must decrement the\n>                 # count by 1\n>                 COMP_CWORD=$((${#COMP_WORDS[@]}-1))\n>         fi\n> fi\n>\n> # Call _git() or _gitk() of the bash script, based on the first\n> # element of the command-line\n> _${COMP_WORDS[0]}\n>\n> IFS=$'\\n'\n> echo \"${COMPREPLY[*]}\"\n> \\EOF\n>\n> complete git  'p/*/`bash ${script} \"${COMMAND_LINE}\" | sort | uniq`/'\n> complete gitk 'p/*/`bash ${script} \"${COMMAND_LINE}\" | sort | uniq`/'\n\nI am worried about 'sort' and 'uniq' being aliased by the user, so I was\nthinking of using '\\sort | \\uniq'\n\nI'll work on the new version of the solution.\n\nThanks again\n\nMarc\n"},{"id":"203345","messageId":"CAMP44s1RtOj6LKCNJ8SX8KSA8eNCMZ+4D-VfQ+WtXju-KhG8ng@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpEdft+L5KW+tMy6Lqm1eUkHQgwWuXaC0UTUdqwW=ohk-Q@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T15:33:09Z","receivedAt":"2012-11-16T15:33:09Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 3:39 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n> On Thu, Nov 15, 2012 at 8:41 PM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> On Thu, Nov 15, 2012 at 12:51 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>>> The current tcsh-completion support for Git, as can be found on the\n>>> Internet, takes the approach of defining the possible completions\n>>> explicitly.  This has the obvious draw-back to require constant\n>>> updating as the Git code base evolves.\n>>>\n>>> The approach taken by this commit is to to re-use the advanced bash\n>>> completion script and use its result for tcsh completion.  This is\n>>> achieved by executing (versus sourcing) the bash script and\n>>> outputting the completion result for tcsh consumption.\n>>>\n>>> Three solutions were looked at to implement this approach with (A)\n>>> being retained:\n>>>\n>>>   A) Modifications:\n>>>           git-completion.bash and new git-completion.tcsh\n>>\n>> As I said, I don't think this is needed. It can be done in a single\n>> stand-alone script without modifications to git-completion.bash.\n>>\n>> This works:\n>\n> Thank you for taking the time to try things out.\n>\n> What you suggest below is an improvement on solution (C).\n> I had chosen (A) instead because (C) creates a third script\n> which gets generated each time a new shell is started.\n\nWe could generate the script only when it's not already present. The\ndisadvantage is that if this script is updated, the helper one would\nnot. One way to solve the problem would be to append the current\nversion of git, and figure a way to query it out. Another would be to\nchecksum it. But then again, maybe it's more expensive to check the\nversion or checksum than just write the file again.\n\nIs it possible to just check if this is a login shell?\n\n>> set called = ($_)\n>\n> I fought with this a lot before posting to the list.\n> It seems that $_ is not set when a double sourcing\n> happens.  Testing the solution as an actual user\n> showed me that when I start a new shell it\n> sources ~/.tcshrc, which then sources ~/.git-completion.tcsh\n> and then $_ is empty for some reason.\n>\n> I couldn't find another way to figure out where the script\n> is located, which is why I had to force the user to use\n> ${HOME} for everything.\n\nAh :(\n\n-- \nFelipe Contreras\n"},{"id":"203346","messageId":"CAFj1UpHLf2je_+b1e5B_5thZ03UYVmW=CWhAh63kNRCbke0kQw@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s1RtOj6LKCNJ8SX8KSA8eNCMZ+4D-VfQ+WtXju-KhG8ng@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-16T15:48:19Z","receivedAt":"2012-11-16T15:48:19Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Fri, Nov 16, 2012 at 10:33 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Fri, Nov 16, 2012 at 3:39 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>> On Thu, Nov 15, 2012 at 8:41 PM, Felipe Contreras\n>> <felipe.contreras@gmail.com> wrote:\n>>> On Thu, Nov 15, 2012 at 12:51 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>>>> The current tcsh-completion support for Git, as can be found on the\n>>>> Internet, takes the approach of defining the possible completions\n>>>> explicitly.  This has the obvious draw-back to require constant\n>>>> updating as the Git code base evolves.\n>>>>\n>>>> The approach taken by this commit is to to re-use the advanced bash\n>>>> completion script and use its result for tcsh completion.  This is\n>>>> achieved by executing (versus sourcing) the bash script and\n>>>> outputting the completion result for tcsh consumption.\n>>>>\n>>>> Three solutions were looked at to implement this approach with (A)\n>>>> being retained:\n>>>>\n>>>>   A) Modifications:\n>>>>           git-completion.bash and new git-completion.tcsh\n>>>\n>>> As I said, I don't think this is needed. It can be done in a single\n>>> stand-alone script without modifications to git-completion.bash.\n>>>\n>>> This works:\n>>\n>> Thank you for taking the time to try things out.\n>>\n>> What you suggest below is an improvement on solution (C).\n>> I had chosen (A) instead because (C) creates a third script\n>> which gets generated each time a new shell is started.\n>\n> We could generate the script only when it's not already present. The\n> disadvantage is that if this script is updated, the helper one would\n> not.\n\nI didn't like that too much either.\n\n> One way to solve the problem would be to append the current\n> version of git, and figure a way to query it out. Another would be to\n> checksum it. But then again, maybe it's more expensive to check the\n> version or checksum than just write the file again.\n\nYeah, I'm also thinking that re-generating the script is not bad enough\nto introduce this complexity.\n\n> Is it possible to just check if this is a login shell?\n\nI think it would be nice to allow the user to manually\nsource git-completion.tcsh, in case they want to make\nmanual modifications to it.\n\nI think the most user-friendly option is to actually re-generate the\nscript each time.  It feels wrong, but it works well :)\n\n>>> set called = ($_)\n>>\n>> I fought with this a lot before posting to the list.\n>> It seems that $_ is not set when a double sourcing\n>> happens.  Testing the solution as an actual user\n>> showed me that when I start a new shell it\n>> sources ~/.tcshrc, which then sources ~/.git-completion.tcsh\n>> and then $_ is empty for some reason.\n>>\n>> I couldn't find another way to figure out where the script\n>> is located, which is why I had to force the user to use\n>> ${HOME} for everything.\n>\n> Ah :(\n>\n> --\n> Felipe Contreras\n"},{"id":"203347","messageId":"CAFj1UpGmoEiLeHPh8LaUGLktV55YbTthi1wMNjLDn6vFMSdMwQ@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpHLf2je_+b1e5B_5thZ03UYVmW=CWhAh63kNRCbke0kQw@mail.gmail.com","subject":"[PATCH v3] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-16T16:12:41Z","receivedAt":"2012-11-16T16:12:41Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"The current tcsh-completion support for Git, as can be found on the\nInternet, takes the approach of defining the possible completions\nexplicitly.  This has the obvious draw-back to require constant\nupdating as the Git code base evolves.\n\nThe approach taken by this commit is to to re-use the advanced bash\ncompletion script and use its result for tcsh completion.  This is\nachieved by sourcing the bash script and outputting the completion\nresult for tcsh consumption.\n\nThree solutions were looked at to implement this approach with (C)\nbeing retained:\n\n  A) Modifications:\n          git-completion.bash and new git-completion.tcsh\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash.\n     When being executed, the script will output the result of the\n     computed completion to be re-used elsewhere (e.g., in tcsh).\n\n     The modification to git-completion.bash is made not to be\n     tcsh-specific, but to allow future users to also re-use its\n     output.  Therefore, to be general, git-completion.bash accepts a\n     second optional parameter, which is not used by tcsh, but could\n     prove useful for other users.\n\n     Pros:\n       1- allows the git-completion.bash script to easily be re-used\n       2- tcsh support is mostly isolated in git-completion.tcsh\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n\n  B) Modifications:\n          git-completion.bash\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash,\n     and sourced using tcsh.\n\n     Pros:\n       1- only requires the user to deal with a single file\n       2- maintenance more obvious for tcsh since it is entirely part\n          of the same git-completion.bash script.\n     Cons:\n       1- tcsh support could affect bash support as they share the\n          same script\n       2- small tcsh section must use syntax suitable for both tcsh\n          and bash and must be at the beginning of the script\n       3- requires script to have a fixed name and location:\n          ${HOME}/.git-completion.sh (for tcsh users only)\n\n  C) Modifications:\n          New git-completion.tcsh\n\n     Provide a short tcsh script that generates another script\n     which extends git-completion.bash.  This new script can be\n     used by tcsh to perform completion.\n\n     Pros:\n       1- tcsh support is entirely isolated in git-completion.tcsh\n       2- new tcsh script can be as complex as needed\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n       3- sourcing the new script will generate a third script\n\nApproach (C) was selected avoid any modification to git-completion.bash.\n\nSigned-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n---\n\nHere's another version which adds contrib/completion/git-completion.tcsh but\ndoes not modify contrib/completion/git-completion.bash at all.\n\n(Sorry, but I still can't get gmail to stop changing the tabs for spaces)\n\nThanks in advance.\n\nMarc\n\n contrib/completion/git-completion.tcsh | 63 ++++++++++++++++++++++++++++++++++\n 1 file changed, 63 insertions(+)\n create mode 100644 contrib/completion/git-completion.tcsh\n\ndiff --git a/contrib/completion/git-completion.tcsh\nb/contrib/completion/git-completion.tcsh\nnew file mode 100644\nindex 0000000..76395f9\n--- /dev/null\n+++ b/contrib/completion/git-completion.tcsh\n@@ -0,0 +1,63 @@\n+#!tcsh\n+#\n+# tcsh completion support for core Git.\n+#\n+# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# When sourced, this script will generate a new script that uses\n+# the git-completion.bash script provided by core Git.  This new\n+# script can be used by tcsh to perform git completion.\n+# The current script also issues the necessary tcsh 'complete'\n+# commands.\n+#\n+# To use this completion script:\n+#\n+#    1) Copy both this file and the bash completion script to ${HOME}.\n+#       You _must_ use the name ${HOME}/.git-completion.bash for the\n+#       bash script.\n+#       (e.g. ~/.git-completion.tcsh and ~/.git-completion.bash).\n+#    2) Add the following line to your .tcshrc/.cshrc:\n+#        source ~/.git-completion.tcsh\n+\n+set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash\n+set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash\n+\n+cat << EOF > ${__git_tcsh_completion_script}\n+#!bash\n+#\n+# This script is GENERATED and will be overwritten automatically.\n+# Do not modify it directly.  Instead, modify the git-completion.tcsh\n+# script provided by Git core.\n+#\n+\n+source ${__git_tcsh_completion_original_script}\n+\n+# Set COMP_WORDS in a way that can be handled by the bash script.\n+COMP_WORDS=(\\$1)\n+\n+# The cursor is at the end of parameter #1.\n+# We must check for a space as the last character which will\n+# tell us that the previous word is complete and the cursor\n+# is on the next word.\n+if [ \"\\${1: -1}\" == \" \" ]; then\n+       # The last character is a space, so our location is at the end\n+       # of the command-line array\n+       COMP_CWORD=\\${#COMP_WORDS[@]}\n+else\n+       # The last character is not a space, so our location is on the\n+       # last word of the command-line array, so we must decrement the\n+       # count by 1\n+       COMP_CWORD=\\$((\\${#COMP_WORDS[@]}-1))\n+fi\n+\n+# Call _git() or _gitk() of the bash script, based on the first\n+# element of the command-line\n+_\\${COMP_WORDS[0]}\n+\n+IFS=\\$'\\n'\n+echo \"\\${COMPREPLY[*]}\"\n+EOF\n+\n+complete git  'p/*/`bash ${__git_tcsh_completion_script}\n\"${COMMAND_LINE}\" | \\sort | \\uniq`/'\n+complete gitk 'p/*/`bash ${__git_tcsh_completion_script}\n\"${COMMAND_LINE}\" | \\sort | \\uniq`/'\n--\n1.8.0.1.g9fe2839\n"},{"id":"203350","messageId":"CAMP44s1RvMSBu2RJqKw9ne4cJyMO4dbFc-gW2HgsN2-uviv=fA@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpHLf2je_+b1e5B_5thZ03UYVmW=CWhAh63kNRCbke0kQw@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T17:18:50Z","receivedAt":"2012-11-16T17:18:50Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 4:48 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n> On Fri, Nov 16, 2012 at 10:33 AM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n\n>> Is it possible to just check if this is a login shell?\n>\n> I think it would be nice to allow the user to manually\n> source git-completion.tcsh, in case they want to make\n> manual modifications to it.\n\nYeah, they could still do that... because they would be running in a\nlogin shell.\n\nWhat I meant is that if the user does: tcsh\nmy_script_that_has_nothing_to_do_with_completion.sh, they would not be\nexecuting this whole script.\n\n> I think the most user-friendly option is to actually re-generate the\n> script each time.  It feels wrong, but it works well :)\n\nI'm not too strongly opposed to add that function to the bash\ncompletion, but to do it only for tcsh doesn't sound right, specially\nwhen there are other alternatives. Correct me if I'm wrong, but very\nfew people use tcsh.\n\n-- \nFelipe Contreras\n"},{"id":"203351","messageId":"CAMP44s3rwUw1QaADgm0xVOK3ebPNVSa06QdN5voNniD2acsz0g@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpGmoEiLeHPh8LaUGLktV55YbTthi1wMNjLDn6vFMSdMwQ@mail.gmail.com","subject":"Re: [PATCH v3] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T17:21:11Z","receivedAt":"2012-11-16T17:21:11Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 5:12 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n\n> diff --git a/contrib/completion/git-completion.tcsh\n> b/contrib/completion/git-completion.tcsh\n> new file mode 100644\n> index 0000000..76395f9\n> --- /dev/null\n> +++ b/contrib/completion/git-completion.tcsh\n> @@ -0,0 +1,63 @@\n> +#!tcsh\n> +#\n> +# tcsh completion support for core Git.\n> +#\n> +# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n> +# Distributed under the GNU General Public License, version 2.0.\n> +#\n> +# When sourced, this script will generate a new script that uses\n> +# the git-completion.bash script provided by core Git.  This new\n> +# script can be used by tcsh to perform git completion.\n> +# The current script also issues the necessary tcsh 'complete'\n> +# commands.\n> +#\n> +# To use this completion script:\n> +#\n> +#    1) Copy both this file and the bash completion script to ${HOME}.\n> +#       You _must_ use the name ${HOME}/.git-completion.bash for the\n> +#       bash script.\n> +#       (e.g. ~/.git-completion.tcsh and ~/.git-completion.bash).\n> +#    2) Add the following line to your .tcshrc/.cshrc:\n> +#        source ~/.git-completion.tcsh\n> +\n> +set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash\n> +set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash\n> +\n> +cat << EOF > ${__git_tcsh_completion_script}\n> +#!bash\n> +#\n> +# This script is GENERATED and will be overwritten automatically.\n> +# Do not modify it directly.  Instead, modify the git-completion.tcsh\n> +# script provided by Git core.\n> +#\n> +\n> +source ${__git_tcsh_completion_original_script}\n> +\n> +# Set COMP_WORDS in a way that can be handled by the bash script.\n> +COMP_WORDS=(\\$1)\n> +\n> +# The cursor is at the end of parameter #1.\n> +# We must check for a space as the last character which will\n> +# tell us that the previous word is complete and the cursor\n> +# is on the next word.\n> +if [ \"\\${1: -1}\" == \" \" ]; then\n> +       # The last character is a space, so our location is at the end\n> +       # of the command-line array\n> +       COMP_CWORD=\\${#COMP_WORDS[@]}\n> +else\n> +       # The last character is not a space, so our location is on the\n> +       # last word of the command-line array, so we must decrement the\n> +       # count by 1\n> +       COMP_CWORD=\\$((\\${#COMP_WORDS[@]}-1))\n> +fi\n> +\n> +# Call _git() or _gitk() of the bash script, based on the first\n> +# element of the command-line\n> +_\\${COMP_WORDS[0]}\n> +\n> +IFS=\\$'\\n'\n> +echo \"\\${COMPREPLY[*]}\"\n> +EOF\n> +\n> +complete git  'p/*/`bash ${__git_tcsh_completion_script}\n> \"${COMMAND_LINE}\" | \\sort | \\uniq`/'\n> +complete gitk 'p/*/`bash ${__git_tcsh_completion_script}\n> \"${COMMAND_LINE}\" | \\sort | \\uniq`/'\n\nThis looks good to me. Except that maybe the sort and uniq can be\nmoved to inside the script.\n\n-- \nFelipe Contreras\n"},{"id":"203355","messageId":"CAFj1UpHMc-bHJgSZKY13YH_69TXkz-50g5xpLA6C+Eh0aqcN9A@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s1RvMSBu2RJqKw9ne4cJyMO4dbFc-gW2HgsN2-uviv=fA@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-16T18:20:31Z","receivedAt":"2012-11-16T18:20:31Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Fri, Nov 16, 2012 at 12:18 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Fri, Nov 16, 2012 at 4:48 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>> On Fri, Nov 16, 2012 at 10:33 AM, Felipe Contreras\n>> <felipe.contreras@gmail.com> wrote:\n>\n>>> Is it possible to just check if this is a login shell?\n>>\n>> I think it would be nice to allow the user to manually\n>> source git-completion.tcsh, in case they want to make\n>> manual modifications to it.\n>\n> Yeah, they could still do that... because they would be running in a\n> login shell.\n>\n> What I meant is that if the user does: tcsh\n> my_script_that_has_nothing_to_do_with_completion.sh, they would not be\n> executing this whole script.\n\nOh, I see now.\n\nI can put a check in the script for the existence of the $prompt variable.\nThis will indicate if it is a login shell or not.\nHowever, a good .cshrc file should already have such a check to avoid\nsourcing a bunch of useless things.  So, I personally think that we\nshould not add it to the git-completion.tcsh script but let the tcsh\nuser decide to do it herself.  But I don't mind being overruled :)\n\n>> I think the most user-friendly option is to actually re-generate the\n>> script each time.  It feels wrong, but it works well :)\n>\n> I'm not too strongly opposed to add that function to the bash\n> completion, but to do it only for tcsh doesn't sound right, specially\n> when there are other alternatives.\n\nI agree, and this is why I made the proposed\n__git_complete_with_output () generic.  That way it could be\nused by other shells or programs.  But at this time, only tcsh\nwould make use of it.\n\nIf you think having __git_complete_with_output () could\nbe useful for others, I think we should go with solution (A).\nIf you don't think so, or if it is better to wait until a need\narises first, then solution (C) will work fine.\n\n> Correct me if I'm wrong, but very few people use tcsh.\n\nLess than I originally thought, when I started working\non this patch :-\\  But I'm still hoping that the those people\nwill be a little happier with their git completion.\n\nMarc\n\n>\n> --\n> Felipe Contreras\n"},{"id":"203356","messageId":"CAFj1UpEMugSrGv53ajvCm=F_wOFm4qr1bnsR5NRPsvgC_fRs5Q@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s3rwUw1QaADgm0xVOK3ebPNVSa06QdN5voNniD2acsz0g@mail.gmail.com","subject":"[PATCH v4] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-16T18:43:45Z","receivedAt":"2012-11-16T18:43:45Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"The current tcsh-completion support for Git, as can be found on the\nInternet, takes the approach of defining the possible completions\nexplicitly.  This has the obvious draw-back to require constant\nupdating as the Git code base evolves.\n\nThe approach taken by this commit is to to re-use the advanced bash\ncompletion script and use its result for tcsh completion.  This is\nachieved by sourcing the bash script and outputting the completion\nresult for tcsh consumption.\n\nThree solutions were looked at to implement this approach with (C)\nbeing retained:\n\n  A) Modifications:\n          git-completion.bash and new git-completion.tcsh\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash.\n     When being executed, the script will output the result of the\n     computed completion to be re-used elsewhere (e.g., in tcsh).\n\n     The modification to git-completion.bash is made not to be\n     tcsh-specific, but to allow future users to also re-use its\n     output.  Therefore, to be general, git-completion.bash accepts a\n     second optional parameter, which is not used by tcsh, but could\n     prove useful for other users.\n\n     Pros:\n       1- allows the git-completion.bash script to easily be re-used\n       2- tcsh support is mostly isolated in git-completion.tcsh\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n\n  B) Modifications:\n          git-completion.bash\n\n     Modify the existing git-completion.bash script to support\n     being sourced using bash (as now), but also executed using bash,\n     and sourced using tcsh.\n\n     Pros:\n       1- only requires the user to deal with a single file\n       2- maintenance more obvious for tcsh since it is entirely part\n          of the same git-completion.bash script.\n     Cons:\n       1- tcsh support could affect bash support as they share the\n          same script\n       2- small tcsh section must use syntax suitable for both tcsh\n          and bash and must be at the beginning of the script\n       3- requires script to have a fixed name and location:\n          ${HOME}/.git-completion.sh (for tcsh users only)\n\n  C) Modifications:\n          New git-completion.tcsh\n\n     Provide a short tcsh script that generates another script\n     which extends git-completion.bash.  This new script can be\n     used by tcsh to perform completion.\n\n     Pros:\n       1- tcsh support is entirely isolated in git-completion.tcsh\n       2- new tcsh script can be as complex as needed\n     Cons (for tcsh users only):\n       1- requires the user to copy both git-completion.tcsh and\n          git-completion.bash to ${HOME}\n       2- requires bash script to have a fixed name and location:\n          ${HOME}/.git-completion.bash\n       3- sourcing the new script will generate a third script\n\nApproach (C) was selected avoid any modification to git-completion.bash.\n\nSigned-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n---\n\nAs suggested, I put the 'sort | uniq' inside the script.\nIn that case, I don't need to worry about aliases since 'sort |uniq' will\nbe executed in bash, for which the tcsh user surely doesn't have aliases setup.\n\nThanks\n\nMarc\n\n\n contrib/completion/git-completion.tcsh | 63 ++++++++++++++++++++++++++++++++++\n 1 file changed, 63 insertions(+)\n create mode 100644 contrib/completion/git-completion.tcsh\n\ndiff --git a/contrib/completion/git-completion.tcsh\nb/contrib/completion/git-completion.tcsh\nnew file mode 100644\nindex 0000000..f0327fc\n--- /dev/null\n+++ b/contrib/completion/git-completion.tcsh\n@@ -0,0 +1,63 @@\n+#!tcsh\n+#\n+# tcsh completion support for core Git.\n+#\n+# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>\n+# Distributed under the GNU General Public License, version 2.0.\n+#\n+# When sourced, this script will generate a new script that uses\n+# the git-completion.bash script provided by core Git.  This new\n+# script can be used by tcsh to perform git completion.\n+# The current script also issues the necessary tcsh 'complete'\n+# commands.\n+#\n+# To use this completion script:\n+#\n+#    1) Copy both this file and the bash completion script to ${HOME}.\n+#       You _must_ use the name ${HOME}/.git-completion.bash for the\n+#       bash script.\n+#       (e.g. ~/.git-completion.tcsh and ~/.git-completion.bash).\n+#    2) Add the following line to your .tcshrc/.cshrc:\n+#        source ~/.git-completion.tcsh\n+\n+set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash\n+set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash\n+\n+cat << EOF > ${__git_tcsh_completion_script}\n+#!bash\n+#\n+# This script is GENERATED and will be overwritten automatically.\n+# Do not modify it directly.  Instead, modify the git-completion.tcsh\n+# script provided by Git core.\n+#\n+\n+source ${__git_tcsh_completion_original_script}\n+\n+# Set COMP_WORDS in a way that can be handled by the bash script.\n+COMP_WORDS=(\\$1)\n+\n+# The cursor is at the end of parameter #1.\n+# We must check for a space as the last character which will\n+# tell us that the previous word is complete and the cursor\n+# is on the next word.\n+if [ \"\\${1: -1}\" == \" \" ]; then\n+       # The last character is a space, so our location is at the end\n+       # of the command-line array\n+       COMP_CWORD=\\${#COMP_WORDS[@]}\n+else\n+       # The last character is not a space, so our location is on the\n+       # last word of the command-line array, so we must decrement the\n+       # count by 1\n+       COMP_CWORD=\\$((\\${#COMP_WORDS[@]}-1))\n+fi\n+\n+# Call _git() or _gitk() of the bash script, based on the first\n+# element of the command-line\n+_\\${COMP_WORDS[0]}\n+\n+IFS=\\$'\\n'\n+echo \"\\${COMPREPLY[*]}\" | sort | uniq\n+EOF\n+\n+complete git  'p/*/`bash ${__git_tcsh_completion_script} \"${COMMAND_LINE}\"`/'\n+complete gitk 'p/*/`bash ${__git_tcsh_completion_script} \"${COMMAND_LINE}\"`/'\n--\n1.8.0.1.g9fe2839\n"},{"id":"203364","messageId":"7v4nkpmi96.fsf@alter.siamese.dyndns.org","threadId":"32092","inReplyTo":"CAFj1UpEMugSrGv53ajvCm=F_wOFm4qr1bnsR5NRPsvgC_fRs5Q@mail.gmail.com","subject":"Re: [PATCH v4] tcsh-completion re-using git-completion.bash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-11-16T19:59:17Z","receivedAt":"2012-11-16T19:59:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marc Khouzam <marc.khouzam@gmail.com> writes:\n\n> The current tcsh-completion support for Git, as can be found on the\n> Internet, takes the approach of defining the possible completions\n> explicitly.  This has the obvious draw-back to require constant\n> updating as the Git code base evolves.\n> ...\n>   C) Modifications:\n>           New git-completion.tcsh\n>\n>      Provide a short tcsh script that generates another script\n>      which extends git-completion.bash.  This new script can be\n>      used by tcsh to perform completion.\n>\n>      Pros:\n>        1- tcsh support is entirely isolated in git-completion.tcsh\n>        2- new tcsh script can be as complex as needed\n>      Cons (for tcsh users only):\n>        1- requires the user to copy both git-completion.tcsh and\n>           git-completion.bash to ${HOME}\n>        2- requires bash script to have a fixed name and location:\n>           ${HOME}/.git-completion.bash\n>        3- sourcing the new script will generate a third script\n> \n> Approach (C) was selected avoid any modification to git-completion.bash.\n>\n> Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n> ---\n>\n> As suggested, I put the 'sort | uniq' inside the script.\n> In that case, I don't need to worry about aliases since 'sort |uniq' will\n> be executed in bash, for which the tcsh user surely doesn't have aliases setup.\n\nOK, so does this look OK to everybody (it does, looking at the\ndifference between v3 and this one, to me)?\n\nThe patch may deserve a Reviewed-by: by Felipe, by the way.  I can\nadd one while applying.\n\nThanks.\n"},{"id":"203365","messageId":"CAMP44s0-OezE9W5-fCM-LS7vPs0S9q0MwsUyFgu7HBdDq3Xzsg@mail.gmail.com","threadId":"32092","inReplyTo":"7v4nkpmi96.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v4] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T20:01:40Z","receivedAt":"2012-11-16T20:01:40Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 8:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Marc Khouzam <marc.khouzam@gmail.com> writes:\n>\n>> The current tcsh-completion support for Git, as can be found on the\n>> Internet, takes the approach of defining the possible completions\n>> explicitly.  This has the obvious draw-back to require constant\n>> updating as the Git code base evolves.\n>> ...\n>>   C) Modifications:\n>>           New git-completion.tcsh\n>>\n>>      Provide a short tcsh script that generates another script\n>>      which extends git-completion.bash.  This new script can be\n>>      used by tcsh to perform completion.\n>>\n>>      Pros:\n>>        1- tcsh support is entirely isolated in git-completion.tcsh\n>>        2- new tcsh script can be as complex as needed\n>>      Cons (for tcsh users only):\n>>        1- requires the user to copy both git-completion.tcsh and\n>>           git-completion.bash to ${HOME}\n>>        2- requires bash script to have a fixed name and location:\n>>           ${HOME}/.git-completion.bash\n>>        3- sourcing the new script will generate a third script\n>>\n>> Approach (C) was selected avoid any modification to git-completion.bash.\n>>\n>> Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>\n>> ---\n>>\n>> As suggested, I put the 'sort | uniq' inside the script.\n>> In that case, I don't need to worry about aliases since 'sort |uniq' will\n>> be executed in bash, for which the tcsh user surely doesn't have aliases setup.\n>\n> OK, so does this look OK to everybody (it does, looking at the\n> difference between v3 and this one, to me)?\n>\n> The patch may deserve a Reviewed-by: by Felipe, by the way.  I can\n> add one while applying.\n\nThat's fine by me.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203367","messageId":"CAMP44s3S4c7ciJNurxGdS2o_TDJJDkGK73dtCGji+C1NoV+Jvw@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpHMc-bHJgSZKY13YH_69TXkz-50g5xpLA6C+Eh0aqcN9A@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T20:04:06Z","receivedAt":"2012-11-16T20:04:06Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 7:20 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n> On Fri, Nov 16, 2012 at 12:18 PM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> On Fri, Nov 16, 2012 at 4:48 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>>> On Fri, Nov 16, 2012 at 10:33 AM, Felipe Contreras\n>>> <felipe.contreras@gmail.com> wrote:\n>>\n>>>> Is it possible to just check if this is a login shell?\n>>>\n>>> I think it would be nice to allow the user to manually\n>>> source git-completion.tcsh, in case they want to make\n>>> manual modifications to it.\n>>\n>> Yeah, they could still do that... because they would be running in a\n>> login shell.\n>>\n>> What I meant is that if the user does: tcsh\n>> my_script_that_has_nothing_to_do_with_completion.sh, they would not be\n>> executing this whole script.\n>\n> Oh, I see now.\n>\n> I can put a check in the script for the existence of the $prompt variable.\n> This will indicate if it is a login shell or not.\n> However, a good .cshrc file should already have such a check to avoid\n> sourcing a bunch of useless things.  So, I personally think that we\n> should not add it to the git-completion.tcsh script but let the tcsh\n> user decide to do it herself.  But I don't mind being overruled :)\n\nSounds sensible to me.\n\n>>> I think the most user-friendly option is to actually re-generate the\n>>> script each time.  It feels wrong, but it works well :)\n>>\n>> I'm not too strongly opposed to add that function to the bash\n>> completion, but to do it only for tcsh doesn't sound right, specially\n>> when there are other alternatives.\n>\n> I agree, and this is why I made the proposed\n> __git_complete_with_output () generic.  That way it could be\n> used by other shells or programs.  But at this time, only tcsh\n> would make use of it.\n>\n> If you think having __git_complete_with_output () could\n> be useful for others, I think we should go with solution (A).\n> If you don't think so, or if it is better to wait until a need\n> arises first, then solution (C) will work fine.\n\nI don't see how it could be useful to others, and if we find out that\nit could, we can always move the code.\n\n>> Correct me if I'm wrong, but very few people use tcsh.\n>\n> Less than I originally thought, when I started working\n> on this patch :-\\  But I'm still hoping that the those people\n> will be a little happier with their git completion.\n\nI think they would :) But we don't need to modify bash's script for\nthat (for now).\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203371","messageId":"20121116204017.GX12052@goldbirke","threadId":"32092","inReplyTo":"CAMP44s3S4c7ciJNurxGdS2o_TDJJDkGK73dtCGji+C1NoV+Jvw@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-16T20:40:17Z","receivedAt":"2012-11-16T20:40:17Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Nov 16, 2012 at 09:04:06PM +0100, Felipe Contreras wrote:\n> > I agree, and this is why I made the proposed\n> > __git_complete_with_output () generic.  That way it could be\n> > used by other shells or programs.  But at this time, only tcsh\n> > would make use of it.\n> >\n> > If you think having __git_complete_with_output () could\n> > be useful for others, I think we should go with solution (A).\n> > If you don't think so, or if it is better to wait until a need\n> > arises first, then solution (C) will work fine.\n\nI think it would be useful.\n\n> I don't see how it could be useful to others, and if we find out that\n> it could, we can always move the code.\n\nFor zsh, perhaps?\n\nAs I understand the main issues with using the completion script with\nzsh are the various little incompatibilities between the two shells\nand bugs in zsh's emulation of Bash's completion-related builtins.\nRunning the completion script under Bash and using its results in zsh\nwould solve these issues at the root.  And would allow as to remove\nsome if [[ -n ${ZSH_VERSION-} ]] code.\n"},{"id":"203374","messageId":"CAMP44s2UVGKa7XkqPxdxQ2ueSMn=Xn4qihy5JWbDovH85n8BwQ@mail.gmail.com","threadId":"32092","inReplyTo":"20121116204017.GX12052@goldbirke","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T21:03:41Z","receivedAt":"2012-11-16T21:03:41Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 9:40 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> On Fri, Nov 16, 2012 at 09:04:06PM +0100, Felipe Contreras wrote:\n>> > I agree, and this is why I made the proposed\n>> > __git_complete_with_output () generic.  That way it could be\n>> > used by other shells or programs.  But at this time, only tcsh\n>> > would make use of it.\n>> >\n>> > If you think having __git_complete_with_output () could\n>> > be useful for others, I think we should go with solution (A).\n>> > If you don't think so, or if it is better to wait until a need\n>> > arises first, then solution (C) will work fine.\n>\n> I think it would be useful.\n\nFor what?\n\n>> I don't see how it could be useful to others, and if we find out that\n>> it could, we can always move the code.\n>\n> For zsh, perhaps?\n\nNope.\n\n> As I understand the main issues with using the completion script with\n> zsh are the various little incompatibilities between the two shells\n> and bugs in zsh's emulation of Bash's completion-related builtins.\n> Running the completion script under Bash and using its results in zsh\n> would solve these issues at the root.  And would allow as to remove\n> some if [[ -n ${ZSH_VERSION-} ]] code.\n\nWe can remove that code already, because we now have code that is\nsuperior than zsh's bash completion emulation:\n\nhttp://article.gmane.org/gmane.comp.version-control.git/208173\n\nThis is the equivalent of what Marc is doing, except that zsh has no\nproblems running bash's code. Note there's a difference with zsh's\nemulation bash (or rather bourne shell, or k shell), and zsh's\nemulation of bash's _completion_. The former is fine, the later is\nnot.\n\nOf course, people might not be aware of this new script, and would\nexpect sourcing the bash one to work right away. Maybe at some point\nwe might throw a warning to suggest them to use my new script. But I\nthink we should wait a few releases just to make sure that people test\nit and nothing is broken.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203377","messageId":"7vr4ntkzy4.fsf@alter.siamese.dyndns.org","threadId":"32092","inReplyTo":"20121116204017.GX12052@goldbirke","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-11-16T21:20:03Z","receivedAt":"2012-11-16T21:20:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> For zsh, perhaps?\n\nYeah, I was wondering about that.\n\nIf we make zsh completion read output from a little stub in bash\ncompletion, just like Felipe steered this series for tcsh, we do not\nhave to worry about \"zsh does not split words unless emulating a\nshell and here is a way to tell zsh to do so\" kind of stuff in bash\ncompletion.  The point is not about the quality of zsh's emulation\nof (k)sh when it is run under that mode, but is about not having to\nhave that logic in bash-only part in the first place.\n"},{"id":"203378","messageId":"20121116212224.GA12052@goldbirke","threadId":"32092","inReplyTo":"CAMP44s2UVGKa7XkqPxdxQ2ueSMn=Xn4qihy5JWbDovH85n8BwQ@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-16T21:22:24Z","receivedAt":"2012-11-16T21:22:24Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Nov 16, 2012 at 10:03:41PM +0100, Felipe Contreras wrote:\n> On Fri, Nov 16, 2012 at 9:40 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> > On Fri, Nov 16, 2012 at 09:04:06PM +0100, Felipe Contreras wrote:\n> >> > I agree, and this is why I made the proposed\n> >> > __git_complete_with_output () generic.  That way it could be\n> >> > used by other shells or programs.  But at this time, only tcsh\n> >> > would make use of it.\n> >> >\n> >> > If you think having __git_complete_with_output () could\n> >> > be useful for others, I think we should go with solution (A).\n> >> > If you don't think so, or if it is better to wait until a need\n> >> > arises first, then solution (C) will work fine.\n> >\n> > I think it would be useful.\n> \n> For what?\n\nFor zsh.\n\n> >> I don't see how it could be useful to others, and if we find out that\n> >> it could, we can always move the code.\n> >\n> > For zsh, perhaps?\n> \n> Nope.\n\nSure.\n\n> > As I understand the main issues with using the completion script with\n> > zsh are the various little incompatibilities between the two shells\n> > and bugs in zsh's emulation of Bash's completion-related builtins.\n> > Running the completion script under Bash and using its results in zsh\n> > would solve these issues at the root.  And would allow as to remove\n> > some if [[ -n ${ZSH_VERSION-} ]] code.\n> \n> We can remove that code already, because we now have code that is\n> superior than zsh's bash completion emulation:\n> \n> http://article.gmane.org/gmane.comp.version-control.git/208173\n\nWhich depends on the completion script having a wrapper function\naround compgen filling COMPREPLY.  However, COMPREPLY will be soon\nfilled by hand-rolled code to prevent expansion issues with compgen,\nand there will be no such wrapper.\n\n> This is the equivalent of what Marc is doing, except that zsh has no\n> problems running bash's code. Note there's a difference with zsh's\n> emulation bash (or rather bourne shell, or k shell), and zsh's\n> emulation of bash's _completion_. The former is fine, the later is\n> not.\n\nThere are a couple of constructs supported by Bash but not by zsh,\nwhich we usually try to avoid.\n"},{"id":"203380","messageId":"CAMP44s3pi0iDOho_qYZEutebDNDveWWv6wEAs-C1bs1A_yL+Sg@mail.gmail.com","threadId":"32092","inReplyTo":"20121116212224.GA12052@goldbirke","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T21:46:16Z","receivedAt":"2012-11-16T21:46:16Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 10:22 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> On Fri, Nov 16, 2012 at 10:03:41PM +0100, Felipe Contreras wrote:\n\n>> > As I understand the main issues with using the completion script with\n>> > zsh are the various little incompatibilities between the two shells\n>> > and bugs in zsh's emulation of Bash's completion-related builtins.\n>> > Running the completion script under Bash and using its results in zsh\n>> > would solve these issues at the root.  And would allow as to remove\n>> > some if [[ -n ${ZSH_VERSION-} ]] code.\n>>\n>> We can remove that code already, because we now have code that is\n>> superior than zsh's bash completion emulation:\n>>\n>> http://article.gmane.org/gmane.comp.version-control.git/208173\n>\n> Which depends on the completion script having a wrapper function\n> around compgen filling COMPREPLY.\n\nNo, it does not. Previous incarnations didn't have this dependency:\n\nhttp://article.gmane.org/gmane.comp.version-control.git/196720\n\nI just thought it was neater this way.\n\n> However, COMPREPLY will be soon\n> filled by hand-rolled code to prevent expansion issues with compgen,\n> and there will be no such wrapper.\n\nI'm still waiting to see a resemblance of that code, but my bet would\nbe that there will be a way to fill both COMPREPLY, and call zsh's\ncompadd. But it's hard to figure that out without any code. Which is\nwhy I'm thinking on doing it myself.\n\nBut even in that case, if push comes to shoves, this zsh wrapper can\nultimately read COMPREPLY and figure things backwards, as even more\nprevious versions did:\n\nhttp://article.gmane.org/gmane.comp.version-control.git/189310\n\n>> This is the equivalent of what Marc is doing, except that zsh has no\n>> problems running bash's code. Note there's a difference with zsh's\n>> emulation bash (or rather bourne shell, or k shell), and zsh's\n>> emulation of bash's _completion_. The former is fine, the later is\n>> not.\n>\n> There are a couple of constructs supported by Bash but not by zsh,\n> which we usually try to avoid.\n\nYes, and is that a big deal?\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203381","messageId":"CAMP44s0y3UPVT+ndELaKNsWXAPG3kv-Xq_Wf6ONDF3Z99A5zMQ@mail.gmail.com","threadId":"32092","inReplyTo":"7vr4ntkzy4.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-16T21:56:41Z","receivedAt":"2012-11-16T21:56:41Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, Nov 16, 2012 at 10:20 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> SZEDER Gábor <szeder@ira.uka.de> writes:\n>\n>> For zsh, perhaps?\n>\n> Yeah, I was wondering about that.\n>\n> If we make zsh completion read output from a little stub in bash\n> completion, just like Felipe steered this series for tcsh, we do not\n> have to worry about \"zsh does not split words unless emulating a\n> shell and here is a way to tell zsh to do so\" kind of stuff in bash\n> completion.\n\nDo we worry about that now? If we do, the only reason is because we\nhadn't had a proper wrapper, like the one I'm proposing to merge. So,\nwe had to put things inside if [[ -n ${ZSH_VERSION-} ]]. Those things\nwould move to my wrapper.\n\nThe only exception where we had to change code outside of that chunk\nthat I'm aware of is '8d58c90 completion: Use parse-options raw output\nfor simple long options', which is probably fixed in later versions of\nzsh, and if not, we could always replace those functions inside my\nwrapper.\n\n> The point is not about the quality of zsh's emulation\n> of (k)sh when it is run under that mode, but is about not having to\n> have that logic in bash-only part in the first place.\n\nAs I said, that logic can be moved away _if_ my wrapper is merged. But\nthen again, that would cause regressions to existing users.\n\nMaybe we should warn them right now that they should be using my\nwrapper, and that this method of zsh support would be obsoleted. But\nmy wrapper probably hasn't received enough testing, so do we really\nwant to do that right now?\n\nEither way, I'm confident that whatever code we need can be\nconsolidated in git-completion.zsh, even without having to run bash.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203399","messageId":"20121117105605.GB12052@goldbirke","threadId":"32092","inReplyTo":"CAMP44s3pi0iDOho_qYZEutebDNDveWWv6wEAs-C1bs1A_yL+Sg@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-17T10:56:05Z","receivedAt":"2012-11-17T10:56:05Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Fri, Nov 16, 2012 at 10:46:16PM +0100, Felipe Contreras wrote:\n> On Fri, Nov 16, 2012 at 10:22 PM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> > On Fri, Nov 16, 2012 at 10:03:41PM +0100, Felipe Contreras wrote:\n> \n> >> > As I understand the main issues with using the completion script with\n> >> > zsh are the various little incompatibilities between the two shells\n> >> > and bugs in zsh's emulation of Bash's completion-related builtins.\n> >> > Running the completion script under Bash and using its results in zsh\n> >> > would solve these issues at the root.  And would allow as to remove\n> >> > some if [[ -n ${ZSH_VERSION-} ]] code.\n> >>\n> >> We can remove that code already, because we now have code that is\n> >> superior than zsh's bash completion emulation:\n> >>\n> >> http://article.gmane.org/gmane.comp.version-control.git/208173\n> >\n> > Which depends on the completion script having a wrapper function\n> > around compgen filling COMPREPLY.\n> \n> No, it does not. Previous incarnations didn't have this dependency:\n> \n> http://article.gmane.org/gmane.comp.version-control.git/196720\n\nGood.\n\n> > However, COMPREPLY will be soon\n> > filled by hand-rolled code to prevent expansion issues with compgen,\n> > and there will be no such wrapper.\n> \n> I'm still waiting to see a resemblance of that code, but my bet would\n> be that there will be a way to fill both COMPREPLY, and call zsh's\n> compadd. But it's hard to figure that out without any code. Which is\n> why I'm thinking on doing it myself.\n> \n> But even in that case, if push comes to shoves, this zsh wrapper can\n> ultimately read COMPREPLY and figure things backwards, as even more\n> previous versions did:\n> \n> http://article.gmane.org/gmane.comp.version-control.git/189310\n\nEven better.  I was just going to propose that zsh's completion could\njust read the contents of COMPREPLY at the end of _git() and _gitk(),\nbecause this way no zsh-induced helper functions and changes would be\nneeded to the completion script at all.\n\nHowever, running the completion script with Bash would also prevent\npossible issues caused by incompatibilities between the two shells\nmentioned below.\n\n> >> This is the equivalent of what Marc is doing, except that zsh has no\n> >> problems running bash's code. Note there's a difference with zsh's\n> >> emulation bash (or rather bourne shell, or k shell), and zsh's\n> >> emulation of bash's _completion_. The former is fine, the later is\n> >> not.\n> >\n> > There are a couple of constructs supported by Bash but not by zsh,\n> > which we usually try to avoid.\n> \n> Yes, and is that a big deal?\n\nNot that big, but I wanted to point out that it's not \"fine\" either.\nJust a slight maintenance burden, because we have to pay attention not\nto use such constructs.\n"},{"id":"203414","messageId":"CAMP44s3FFEGJDa6cnwVY0aJkoU_-OdvDPD0gPQtrUqdY2JCpWw@mail.gmail.com","threadId":"32092","inReplyTo":"20121117105605.GB12052@goldbirke","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-17T11:46:27Z","receivedAt":"2012-11-17T11:46:27Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Nov 17, 2012 at 11:56 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> On Fri, Nov 16, 2012 at 10:46:16PM +0100, Felipe Contreras wrote:\n\n>> But even in that case, if push comes to shoves, this zsh wrapper can\n>> ultimately read COMPREPLY and figure things backwards, as even more\n>> previous versions did:\n>>\n>> http://article.gmane.org/gmane.comp.version-control.git/189310\n>\n> Even better.  I was just going to propose that zsh's completion could\n> just read the contents of COMPREPLY at the end of _git() and _gitk(),\n> because this way no zsh-induced helper functions and changes would be\n> needed to the completion script at all.\n\nI would rather modify the __gitcomp function. Parsing COMPREPLY is too\ncumbersome.\n\n> However, running the completion script with Bash would also prevent\n> possible issues caused by incompatibilities between the two shells\n> mentioned below.\n\nIt could, but it doesn't now.\n\n>> >> This is the equivalent of what Marc is doing, except that zsh has no\n>> >> problems running bash's code. Note there's a difference with zsh's\n>> >> emulation bash (or rather bourne shell, or k shell), and zsh's\n>> >> emulation of bash's _completion_. The former is fine, the later is\n>> >> not.\n>> >\n>> > There are a couple of constructs supported by Bash but not by zsh,\n>> > which we usually try to avoid.\n>>\n>> Yes, and is that a big deal?\n>\n> Not that big, but I wanted to point out that it's not \"fine\" either.\n> Just a slight maintenance burden, because we have to pay attention not\n> to use such constructs.\n\nDo we have to pay attention?\n\nI say when we encounter one of such maintenance burden issues _then_\nwe think about it. In the meantime for all we know sourcing bash's\nscript from zsh is fine.\n\n-- \nFelipe Contreras\n"},{"id":"203421","messageId":"20121117141714.GJ12052@goldbirke","threadId":"32092","inReplyTo":"CAMP44s3FFEGJDa6cnwVY0aJkoU_-OdvDPD0gPQtrUqdY2JCpWw@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2012-11-17T14:17:14Z","receivedAt":"2012-11-17T14:17:14Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"On Sat, Nov 17, 2012 at 12:46:27PM +0100, Felipe Contreras wrote:\n> On Sat, Nov 17, 2012 at 11:56 AM, SZEDER Gábor <szeder@ira.uka.de> wrote:\n> > On Fri, Nov 16, 2012 at 10:46:16PM +0100, Felipe Contreras wrote:\n> \n> >> But even in that case, if push comes to shoves, this zsh wrapper can\n> >> ultimately read COMPREPLY and figure things backwards, as even more\n> >> previous versions did:\n> >>\n> >> http://article.gmane.org/gmane.comp.version-control.git/189310\n> >\n> > Even better.  I was just going to propose that zsh's completion could\n> > just read the contents of COMPREPLY at the end of _git() and _gitk(),\n> > because this way no zsh-induced helper functions and changes would be\n> > needed to the completion script at all.\n> \n> I would rather modify the __gitcomp function. Parsing COMPREPLY is too\n> cumbersome.\n\nEach element of COMPREPLY contains a possible completion word.  What\nparsing is needed to use that, that is so cumbersome?\n\n> > However, running the completion script with Bash would also prevent\n> > possible issues caused by incompatibilities between the two shells\n> > mentioned below.\n> \n> It could, but it doesn't now.\n> \n> >> >> This is the equivalent of what Marc is doing, except that zsh has no\n> >> >> problems running bash's code. Note there's a difference with zsh's\n> >> >> emulation bash (or rather bourne shell, or k shell), and zsh's\n> >> >> emulation of bash's _completion_. The former is fine, the later is\n> >> >> not.\n> >> >\n> >> > There are a couple of constructs supported by Bash but not by zsh,\n> >> > which we usually try to avoid.\n> >>\n> >> Yes, and is that a big deal?\n> >\n> > Not that big, but I wanted to point out that it's not \"fine\" either.\n> > Just a slight maintenance burden, because we have to pay attention not\n> > to use such constructs.\n> \n> Do we have to pay attention?\n\nUnless you don't mind possible breakages of zsh completion, yes.\n\n> I say when we encounter one of such maintenance burden issues _then_\n> we think about it. In the meantime for all we know sourcing bash's\n> script from zsh is fine.\n\nThat's a cool argument, will remember it when it again comes to\nrefactoring the __gitcomp() tests.  For now those tests work just\nfine.  When we encounter maintenance burden issues, like fixing a bug\nrequiring the same modification to all of those tests, then we'll\nthink about it. ;)\n"},{"id":"203428","messageId":"CAFj1UpFbuHVhPOQVB9-sPjW2aBN=H+OUyYnz00qASZ5ssbwmGw@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s0y3UPVT+ndELaKNsWXAPG3kv-Xq_Wf6ONDF3Z99A5zMQ@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-17T17:15:54Z","receivedAt":"2012-11-17T17:15:54Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Fri, Nov 16, 2012 at 4:56 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Fri, Nov 16, 2012 at 10:20 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>\n>> The point is not about the quality of zsh's emulation\n>> of (k)sh when it is run under that mode, but is about not having to\n>> have that logic in bash-only part in the first place.\n>\n> As I said, that logic can be moved away _if_ my wrapper is merged. But\n> then again, that would cause regressions to existing users.\n\nPlease forgive me as I don't know the background of the efforts for\nzsh git-completion or\nthe syntax for zsh completion, but I thought I'd mention another\napproach I tried for tcsh\nwhich may work for zsh.\n\nI gather that using a wrapper for zsh causes concerns about\nbackwards-compatibility.\nSo, what could be done is have the bash script do both jobs: setup the\nzsh completion\ncommands, and output the git completion using bash itself.  At the top\nof git-completion.bash\n(or it could be even pushed at the bottom using if/else) we could use:\n\nif [[ -n ${ZSH_VERSION-} ]]; then\n  # replace below by zsh completion commands calling `bash\n${HOME}/.git-completion.bash`\n  complete git   'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'\n  complete gitk 'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'\n  exit\nfi\n\nThat way the zsh user would still simply do 'source\n~/.git-completion.bash' which would\nonly execute the two zsh completion setup commands.  Then, when completion is\ntriggered, it calls `bash ${HOME}/.git-completion.bash ${COMMAND_LINE}` and\nprocesses the output like tcsh does.  This limits the zsh-specific\ncode to 2 lines for\nthe entire script.\n\nI got this to work for tcsh (solution (B)) adding the following a the top of\ngit-completion.bash:\n\ntest \"$tcsh\" != \"\" && \\\n   complete git  'p,*,`${HOME}/.git-completion.sh\n\"${COMMAND_LINE}\"|\\sort|\\uniq`,' && \\\n   complete gitk 'p,*,`${HOME}/.git-completion.sh\n\"${COMMAND_LINE}\"|\\sort|\\uniq`,' && \\\n   exit\n\nbut I didn't think people would go for that since those lines have to\nwork in both bash\nand tcsh syntax.  I thought this made the script a bit brittle.\n\nJust a thought.\n\nMarc\n"},{"id":"203429","messageId":"CAMP44s30wYnkQdq8yup3z-t=FEf1R+k8OC-o7-uY=19z9VHDPg@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpFbuHVhPOQVB9-sPjW2aBN=H+OUyYnz00qASZ5ssbwmGw@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-17T18:01:23Z","receivedAt":"2012-11-17T18:01:23Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sat, Nov 17, 2012 at 6:15 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n> On Fri, Nov 16, 2012 at 4:56 PM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> On Fri, Nov 16, 2012 at 10:20 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>>\n>>> The point is not about the quality of zsh's emulation\n>>> of (k)sh when it is run under that mode, but is about not having to\n>>> have that logic in bash-only part in the first place.\n>>\n>> As I said, that logic can be moved away _if_ my wrapper is merged. But\n>> then again, that would cause regressions to existing users.\n>\n> Please forgive me as I don't know the background of the efforts for\n> zsh git-completion or\n> the syntax for zsh completion, but I thought I'd mention another\n> approach I tried for tcsh\n> which may work for zsh.\n>\n> I gather that using a wrapper for zsh causes concerns about\n> backwards-compatibility.\n\nI don't see any concerns.\n\n> if [[ -n ${ZSH_VERSION-} ]]; then\n>   # replace below by zsh completion commands calling `bash\n> ${HOME}/.git-completion.bash`\n\n>   complete git   'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'\n>   complete gitk 'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'\n\nThat doesn't work in zsh. It might be possible to do something\nsimilar, but it would probably require many more lines.\n\nAnd we can achieve the same by essentially moving the relevant code of\nmy wrapper:\n\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -23,10 +23,6 @@\n #    3) Consider changing your PS1 to also show the current branch,\n #       see git-prompt.sh for details.\n\n-if [[ -n ${ZSH_VERSION-} ]]; then\n-       autoload -U +X bashcompinit && bashcompinit\n-fi\n-\n case \"$COMP_WORDBREAKS\" in\n *:*) : great ;;\n *)   COMP_WORDBREAKS=\"$COMP_WORDBREAKS:\"\n@@ -2404,6 +2400,32 @@ __gitk_main ()\n        __git_complete_revlist\n }\n\n+if [[ -n ${ZSH_VERSION-} ]]; then\n+       emulate -L zsh\n+\n+       __gitcompadd ()\n+       {\n+               compadd -Q -S \"$4\" -P \"${(M)cur#*[=:]}\" -p \"$2\" --\n${=1} && _ret=0\n+       }\n+\n+       _git ()\n+       {\n+               local _ret=1\n+               () {\n+                 emulate -L ksh\n+                       local cur cword prev\n+                       cur=${words[CURRENT-1]}\n+                       prev=${words[CURRENT-2]}\n+                       let cword=CURRENT-1\n+                       __${service}_main\n+               }\n+               let _ret && _default -S '' && _ret=0\n+               return _ret\n+       }\n+       compdef _git git gitk\n+       return\n+fi\n+\n __git_func_wrap ()\n {\n        if [[ -n ${ZSH_VERSION-} ]]; then\n\n-- \nFelipe Contreras\n"},{"id":"203560","messageId":"CAFj1UpHs08seVH8Kb3CuoNTaF+x6vA+ybVTEu0TyLX8NYuuidQ@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s30wYnkQdq8yup3z-t=FEf1R+k8OC-o7-uY=19z9VHDPg@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-20T14:58:50Z","receivedAt":"2012-11-20T14:58:50Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Sat, Nov 17, 2012 at 1:01 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n>\n>> I gather that using a wrapper for zsh causes concerns about\n>> backwards-compatibility.\n>\n> I don't see any concerns.\n>\n>> if [[ -n ${ZSH_VERSION-} ]]; then\n>>   # replace below by zsh completion commands calling `bash\n>> ${HOME}/.git-completion.bash`\n>\n>>   complete git   'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'\n>>   complete gitk 'p/*/`bash ${HOME}/.git-completion.bash ${COMMAND_LINE}`/'\n>\n> That doesn't work in zsh. It might be possible to do something\n> similar, but it would probably require many more lines.\n\nHi,\n\nsince there doesn't seem to be an agreement that the approach to achieve tcsh\ngit-completion would be useful for zsh (the other possible shell that could use\nit is ksh, but I haven't looked into that), maybe the simplest thing\nis to keep the\ntcsh solution contained in a tcsh-only script.  This is the latest solution as\nproposed here:\n\n[1] http://www.mail-archive.com/git@vger.kernel.org/msg12192.html\n\nFor reference, the more general solution was proposed here:\n[2] http://www.mail-archive.com/git@vger.kernel.org/msg12122.html\n\nIf there is interest in merging [1], please let me know and I'll post another\nversion which adds a check to make sure that the user properly copied\ngit-completion.bash to be used by the new git-completion.tcsh.\n\nThanks for your input.\n\nMarc\n"},{"id":"203561","messageId":"CAMP44s1i59VtX9xMmM-j3Gzcufg6jtKy34MMuwrfenmSw3oLAg@mail.gmail.com","threadId":"32092","inReplyTo":"CAFj1UpHs08seVH8Kb3CuoNTaF+x6vA+ybVTEu0TyLX8NYuuidQ@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-11-20T15:15:17Z","receivedAt":"2012-11-20T15:15:17Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Tue, Nov 20, 2012 at 3:58 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n\n> Hi,\n>\n> since there doesn't seem to be an agreement that the approach to achieve tcsh\n> git-completion would be useful for zsh (the other possible shell that could use\n> it is ksh, but I haven't looked into that), maybe the simplest thing\n> is to keep the\n> tcsh solution contained in a tcsh-only script.  This is the latest solution as\n> proposed here:\n>\n> [1] http://www.mail-archive.com/git@vger.kernel.org/msg12192.html\n\nThis one is already merged to 'next'.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"203563","messageId":"CAFj1UpFTu7GnpKSvs6qGH6XjAT16RAk4rmdX0sPFOo9ABg8BKg@mail.gmail.com","threadId":"32092","inReplyTo":"CAMP44s1i59VtX9xMmM-j3Gzcufg6jtKy34MMuwrfenmSw3oLAg@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@gmail.com","sentAt":"2012-11-20T18:20:15Z","receivedAt":"2012-11-20T18:20:15Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"On Tue, Nov 20, 2012 at 10:15 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Tue, Nov 20, 2012 at 3:58 PM, Marc Khouzam <marc.khouzam@gmail.com> wrote:\n>\n>> Hi,\n>>\n>> since there doesn't seem to be an agreement that the approach to achieve tcsh\n>> git-completion would be useful for zsh (the other possible shell that could use\n>> it is ksh, but I haven't looked into that), maybe the simplest thing\n>> is to keep the\n>> tcsh solution contained in a tcsh-only script.  This is the latest solution as\n>> proposed here:\n>>\n>> [1] http://www.mail-archive.com/git@vger.kernel.org/msg12192.html\n>\n> This one is already merged to 'next'.\n\nAwesome!  I didn't notice.\n\nIf I want to suggest an improvement (like checking if the bash script\nis available),\ndo I just post a patch here?\n\nThanks a lot for moving forward with this so quickly!\n\nMarc\n"},{"id":"203572","messageId":"7vzk2cq8y9.fsf@alter.siamese.dyndns.org","threadId":"32092","inReplyTo":"CAFj1UpFTu7GnpKSvs6qGH6XjAT16RAk4rmdX0sPFOo9ABg8BKg@mail.gmail.com","subject":"Re: [PATCH] tcsh-completion re-using git-completion.bash","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-11-20T21:07:58Z","receivedAt":"2012-11-20T21:07:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Marc Khouzam <marc.khouzam@gmail.com> writes:\n\n>> This one is already merged to 'next'.\n>\n> Awesome!  I didn't notice.\n>\n> If I want to suggest an improvement (like checking if the bash\n> script is available), do I just post a patch here?\n\nYes, as a follow-up patch (or two).\n\nThanks.\n"}]}