Skip to content

Commit c1640aa

Browse files
committed
Merge branch 'mk/complete-tcsh' into maint
Command line completion for "tcsh" emitted an unwanted space after completing a single directory name. * mk/complete-tcsh: Prevent space after directories in tcsh completion
2 parents 85fd059 + 92f1c04 commit c1640aa

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

contrib/completion/git-completion.tcsh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#
1414
# To use this completion script:
1515
#
16+
# 0) You need tcsh 6.16.00 or newer.
1617
# 1) Copy both this file and the bash completion script to ${HOME}.
1718
# You _must_ use the name ${HOME}/.git-completion.bash for the
1819
# bash script.
@@ -24,6 +25,15 @@
2425
# set autolist=ambiguous
2526
# It will tell tcsh to list the possible completion choices.
2627

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+
2737
set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
2838
set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
2939

@@ -64,9 +74,7 @@ fi
6474
_\${1}
6575
6676
IFS=\$'\n'
67-
if [ \${#COMPREPLY[*]} -gt 0 ]; then
68-
echo "\${COMPREPLY[*]}" | sort | uniq
69-
else
77+
if [ \${#COMPREPLY[*]} -eq 0 ]; then
7078
# No completions suggested. In this case, we want tcsh to perform
7179
# standard file completion. However, there does not seem to be way
7280
# to tell tcsh to do that. To help the user, we try to simulate
@@ -85,19 +93,20 @@ else
8593
# We don't support ~ expansion: too tricky.
8694
if [ "\${TO_COMPLETE:0:1}" != "~" ]; then
8795
# 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\`)
9797
fi
9898
fi
9999
fi
100100
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+
101110
EOF
102111

103112
# Don't need this variable anymore, so don't pollute the users environment

0 commit comments

Comments
 (0)