Support for git aliasing for tcsh completion

tcsh users sometimes alias the 'git' command to another name. In this case, the user expects to only have to issue a new 'complete' command using the alias name. However, the tcsh script currently uses the command typed by the user to call the appropriate function in git-completion.bash, either _git() or _gitk(). When using an alias, this technique no longer works. This change specifies the real name of the command (either 'git' or 'gitk') as a parameter to the script handling tcsh completion. This allows the user to use any alias for the 'git' or 'gitk' commands, while still getting completion to work. A check for the presence of ${HOME}/.git-completion.bash is also added to help the user make use of the script properly. Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Marc Khouzam committed Nov 26, 2012 at 23:13 UTC ce45ea6a133a68ead5d06b33453cc5296fb5c720
1 file changed +12 -7
contrib/completion/git-completion.tcsh
+12 -7
@@ -23,6 +23,12 @@
23 set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
24 set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
25
26 +# Check that the user put the script in the right place
27 +if ( ! -e ${__git_tcsh_completion_original_script} ) then
28 + echo "git-completion.tcsh: Cannot find: ${__git_tcsh_completion_original_script}. Git completion will not work."
29 + exit
30 +endif
31 +
32 cat << EOF > ${__git_tcsh_completion_script}
33 #!bash
34 #
@@ -34,13 +40,13 @@ cat << EOF > ${__git_tcsh_completion_script}
40 source ${__git_tcsh_completion_original_script}
41
42 # Set COMP_WORDS in a way that can be handled by the bash script.
37 -COMP_WORDS=(\$1)
43 +COMP_WORDS=(\$2)
44
45 # The cursor is at the end of parameter #1.
46 # We must check for a space as the last character which will
47 # tell us that the previous word is complete and the cursor
48 # is on the next word.
43 -if [ "\${1: -1}" == " " ]; then
49 +if [ "\${2: -1}" == " " ]; then
50 # The last character is a space, so our location is at the end
51 # of the command-line array
52 COMP_CWORD=\${#COMP_WORDS[@]}
@@ -51,13 +57,12 @@ else
57 COMP_CWORD=\$((\${#COMP_WORDS[@]}-1))
58 fi
59
54 -# Call _git() or _gitk() of the bash script, based on the first
55 -# element of the command-line
56 -_\${COMP_WORDS[0]}
60 +# Call _git() or _gitk() of the bash script, based on the first argument
61 +_\${1}
62
63 IFS=\$'\n'
64 echo "\${COMPREPLY[*]}" | sort | uniq
65 EOF
66
62 -complete git 'p/*/`bash ${__git_tcsh_completion_script} "${COMMAND_LINE}"`/'
63 -complete gitk 'p/*/`bash ${__git_tcsh_completion_script} "${COMMAND_LINE}"`/'
67 +complete git 'p/*/`bash ${__git_tcsh_completion_script} git "${COMMAND_LINE}"`/'
68 +complete gitk 'p/*/`bash ${__git_tcsh_completion_script} gitk "${COMMAND_LINE}"`/'