{"thread":{"id":"32551","subject":"[PATCH] Prevent space after directories in tcsh completion","startedAt":"2013-01-07T19:07:10Z","lastAt":"2014-07-01T17:45:28Z","messageCount":2,"participants":["Marc Khouzam","janparadowski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"206245","messageId":"E59706EF8DB1D147B15BECA3322E4BDC06997E@eusaamb103.ericsson.se","threadId":"32551","inReplyTo":null,"subject":"[PATCH] Prevent space after directories in tcsh completion","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@ericsson.com","sentAt":"2013-01-07T19:07:10Z","receivedAt":"2013-01-07T19:07:10Z","isPatch":true,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"If git-completion.bash returns a single directory as a completion,\ntcsh will automatically add a space after it, which is not what the\nuser wants.\n\nThis commit prevents tcsh from doing this.\n\nAlso, a check is added to make sure the tcsh version used is recent\nenough to allow completion to work as expected.\n\nSigned-off-by: Marc Khouzam <marc.khouzam@ericsson.com>\n---\n\nThis update is meant to have tcsh completion work better if the\nfeature \"git-completion.bash: add support for path completion\"\nis accepted.\nSee http://www.mail-archive.com/git@vger.kernel.org/msg14137.html\nThis commit does not depend on that other feature though and can\nbe applied right away.\n\nFurthermore, based on feedback I received, some users are running\nversions of tcsh that are over 5 years old and don't provide the\nproper support for this script.  I've added a check to let the user\nknow of such (sad) situation nicely.\n\nThanks\n\nMarc\n\n contrib/completion/git-completion.tcsh | 33 +++++++++++++++++++++------------\n 1 file changed, 21 insertions(+), 12 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.tcsh b/contrib/completion/git-completion.tcsh\nindex 8aafb63..3e3889f 100644\n--- a/contrib/completion/git-completion.tcsh\n+++ b/contrib/completion/git-completion.tcsh\n@@ -13,6 +13,7 @@\n #\n # To use this completion script:\n #\n+#    0) You need tcsh 6.16.00 or newer.\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@@ -24,6 +25,15 @@\n #        set autolist=ambiguous\n #       It will tell tcsh to list the possible completion choices.\n \n+set __git_tcsh_completion_version = `\\echo ${tcsh} | \\sed 's/\\./ /g'`\n+if ( ${__git_tcsh_completion_version[1]} < 6 || \\\n+     ( ${__git_tcsh_completion_version[1]} == 6 && \\\n+       ${__git_tcsh_completion_version[2]} < 16 ) ) then\n+\techo \"git-completion.tcsh: Your version of tcsh is too old, you need version 6.16.00 or newer.  Git completion will not work.\"\n+\texit\n+endif\n+unset __git_tcsh_completion_version\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@@ -64,9 +74,7 @@ fi\n _\\${1}\n \n IFS=\\$'\\n'\n-if [ \\${#COMPREPLY[*]} -gt 0 ]; then\n-\techo \"\\${COMPREPLY[*]}\" | sort | uniq\n-else\n+if [ \\${#COMPREPLY[*]} -eq 0 ]; then\n \t# No completions suggested.  In this case, we want tcsh to perform\n \t# standard file completion.  However, there does not seem to be way\n \t# to tell tcsh to do that.  To help the user, we try to simulate\n@@ -85,19 +93,20 @@ else\n \t\t# We don't support ~ expansion: too tricky.\n \t\tif [ \"\\${TO_COMPLETE:0:1}\" != \"~\" ]; then\n \t\t\t# Use ls so as to add the '/' at the end of directories.\n-\t\t\tRESULT=(\\`ls -dp \\${TO_COMPLETE}* 2> /dev/null\\`)\n-\t\t\techo \\${RESULT[*]}\n-\n-\t\t\t# If there is a single completion and it is a directory,\n-\t\t\t# we output it a second time to trick tcsh into not adding a space\n-\t\t\t# after it.\n-\t\t\tif [ \\${#RESULT[*]} -eq 1 ] && [ \"\\${RESULT[0]: -1}\" == \"/\" ]; then\n-\t\t\t\techo \\${RESULT[*]}\n-\t\t\tfi\n+\t\t\tCOMPREPLY=(\\`ls -dp \\${TO_COMPLETE}* 2> /dev/null\\`)\n \t\tfi\n \tfi\n fi\n \n+# tcsh does not automatically remove duplicates, so we do it ourselves\n+echo \"\\${COMPREPLY[*]}\" | sort | uniq\n+\n+# If there is a single completion and it is a directory, we output it\n+# a second time to trick tcsh into not adding a space after it.\n+if [ \\${#COMPREPLY[*]} -eq 1 ] && [ \"\\${COMPREPLY[0]: -1}\" == \"/\" ]; then\n+\techo \"\\${COMPREPLY[*]}\"\n+fi\n+\n EOF\n \n # Don't need this variable anymore, so don't pollute the users environment\n-- \n1.8.1.367.g8e14972.dirty\n"},{"id":"245244","messageId":"1404236728065-7614312.post@n2.nabble.com","threadId":"32551","inReplyTo":"E59706EF8DB1D147B15BECA3322E4BDC06997E@eusaamb103.ericsson.se","subject":"Re: [PATCH] Prevent space after directories in tcsh completion","fromName":"janparadowski","fromEmail":"janp617@gmail.com","sentAt":"2014-07-01T17:45:28Z","receivedAt":"2014-07-01T17:45:28Z","isPatch":true,"sender":{"key":"janp617@gmail.com","avatar":null},"body":"Hello\n\nscript works beautifully except for a small thing:\n\nreporoot> ls \n folder/ folder_file.txt\n\nreproot> git commit fo<TAB>\ncompletes to git commit folderSPACE without presenting the completion\noptions\n\n(git diff fo<TAB> completes as expected to git diff folder and gives the 2\ncompletion options)\n\nis that easily fixable too?\n\n\n\n--\nView this message in context: http://git.661346.n2.nabble.com/PATCH-Prevent-space-after-directories-in-tcsh-completion-tp7574444p7614312.html\nSent from the git mailing list archive at Nabble.com.\n"}]}