Prevent space after directories in tcsh completion
If git-completion.bash returns a single directory as a completion, tcsh will automatically add a space after it, which is not what the user wants. This commit prevents tcsh from doing this. Also, a check is added to make sure the tcsh version used is recent enough to allow completion to work as expected. Signed-off-by: Marc Khouzam <marc.khouzam@ericsson.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Marc Khouzam committed
Jan 7, 2013 at 19:07 UTC
92f1c042432aa20244bcfbd426c4d8bcb1d56fdb
1 file changed
+21
-12
contrib/completion/git-completion.tcsh
+21
-12
@@ -13,6 +13,7 @@
13
#
14
# To use this completion script:
15
#
16
+# 0) You need tcsh 6.16.00 or newer.
17
# 1) Copy both this file and the bash completion script to ${HOME}.
18
# You _must_ use the name ${HOME}/.git-completion.bash for the
19
# bash script.
@@ -24,6 +25,15 @@
25
# set autolist=ambiguous
26
# It will tell tcsh to list the possible completion choices.
27
28
+set __git_tcsh_completion_version = `\echo ${tcsh} | \sed 's/\./ /g'`
29
+if ( ${__git_tcsh_completion_version[1]} < 6 || \
30
+ ( ${__git_tcsh_completion_version[1]} == 6 && \
31
+ ${__git_tcsh_completion_version[2]} < 16 ) ) then
32
+ echo "git-completion.tcsh: Your version of tcsh is too old, you need version 6.16.00 or newer. Git completion will not work."
33
+ exit
34
+endif
35
+unset __git_tcsh_completion_version
36
+
37
set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
38
set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
39
@@ -64,9 +74,7 @@ fi
74
_\${1}
75
76
IFS=\$'\n'
67
-if [ \${#COMPREPLY[*]} -gt 0 ]; then
68
- echo "\${COMPREPLY[*]}" | sort | uniq
69
-else
77
+if [ \${#COMPREPLY[*]} -eq 0 ]; then
78
# No completions suggested. In this case, we want tcsh to perform
79
# standard file completion. However, there does not seem to be way
80
# to tell tcsh to do that. To help the user, we try to simulate
@@ -85,19 +93,20 @@ else
93
# We don't support ~ expansion: too tricky.
94
if [ "\${TO_COMPLETE:0:1}" != "~" ]; then
95
# Use ls so as to add the '/' at the end of directories.
88
- RESULT=(\`ls -dp \${TO_COMPLETE}* 2> /dev/null\`)
89
- echo \${RESULT[*]}
90
-
91
- # If there is a single completion and it is a directory,
92
- # we output it a second time to trick tcsh into not adding a space
93
- # after it.
94
- if [ \${#RESULT[*]} -eq 1 ] && [ "\${RESULT[0]: -1}" == "/" ]; then
95
- echo \${RESULT[*]}
96
- fi
96
+ COMPREPLY=(\`ls -dp \${TO_COMPLETE}* 2> /dev/null\`)
97
fi
98
fi
99
fi
100
101
+# tcsh does not automatically remove duplicates, so we do it ourselves
102
+echo "\${COMPREPLY[*]}" | sort | uniq
103
+
104
+# If there is a single completion and it is a directory, we output it
105
+# a second time to trick tcsh into not adding a space after it.
106
+if [ \${#COMPREPLY[*]} -eq 1 ] && [ "\${COMPREPLY[0]: -1}" == "/" ]; then
107
+ echo "\${COMPREPLY[*]}"
108
+fi
109
+
110
EOF
111
112
# Don't need this variable anymore, so don't pollute the users environment