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>
This commit is contained in:
parent
9673b8c392
commit
ce45ea6a13
@ -23,6 +23,12 @@
|
|||||||
set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
|
set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
|
||||||
set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
|
set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
|
||||||
|
|
||||||
|
# Check that the user put the script in the right place
|
||||||
|
if ( ! -e ${__git_tcsh_completion_original_script} ) then
|
||||||
|
echo "git-completion.tcsh: Cannot find: ${__git_tcsh_completion_original_script}. Git completion will not work."
|
||||||
|
exit
|
||||||
|
endif
|
||||||
|
|
||||||
cat << EOF > ${__git_tcsh_completion_script}
|
cat << EOF > ${__git_tcsh_completion_script}
|
||||||
#!bash
|
#!bash
|
||||||
#
|
#
|
||||||
@ -34,13 +40,13 @@ cat << EOF > ${__git_tcsh_completion_script}
|
|||||||
source ${__git_tcsh_completion_original_script}
|
source ${__git_tcsh_completion_original_script}
|
||||||
|
|
||||||
# Set COMP_WORDS in a way that can be handled by the bash script.
|
# Set COMP_WORDS in a way that can be handled by the bash script.
|
||||||
COMP_WORDS=(\$1)
|
COMP_WORDS=(\$2)
|
||||||
|
|
||||||
# The cursor is at the end of parameter #1.
|
# The cursor is at the end of parameter #1.
|
||||||
# We must check for a space as the last character which will
|
# We must check for a space as the last character which will
|
||||||
# tell us that the previous word is complete and the cursor
|
# tell us that the previous word is complete and the cursor
|
||||||
# is on the next word.
|
# is on the next word.
|
||||||
if [ "\${1: -1}" == " " ]; then
|
if [ "\${2: -1}" == " " ]; then
|
||||||
# The last character is a space, so our location is at the end
|
# The last character is a space, so our location is at the end
|
||||||
# of the command-line array
|
# of the command-line array
|
||||||
COMP_CWORD=\${#COMP_WORDS[@]}
|
COMP_CWORD=\${#COMP_WORDS[@]}
|
||||||
@ -51,13 +57,12 @@ else
|
|||||||
COMP_CWORD=\$((\${#COMP_WORDS[@]}-1))
|
COMP_CWORD=\$((\${#COMP_WORDS[@]}-1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Call _git() or _gitk() of the bash script, based on the first
|
# Call _git() or _gitk() of the bash script, based on the first argument
|
||||||
# element of the command-line
|
_\${1}
|
||||||
_\${COMP_WORDS[0]}
|
|
||||||
|
|
||||||
IFS=\$'\n'
|
IFS=\$'\n'
|
||||||
echo "\${COMPREPLY[*]}" | sort | uniq
|
echo "\${COMPREPLY[*]}" | sort | uniq
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
complete git 'p/*/`bash ${__git_tcsh_completion_script} "${COMMAND_LINE}"`/'
|
complete git 'p/*/`bash ${__git_tcsh_completion_script} git "${COMMAND_LINE}"`/'
|
||||||
complete gitk 'p/*/`bash ${__git_tcsh_completion_script} "${COMMAND_LINE}"`/'
|
complete gitk 'p/*/`bash ${__git_tcsh_completion_script} gitk "${COMMAND_LINE}"`/'
|
||||||
|
Loading…
Reference in New Issue
Block a user