contrib / completion / git-completion.tcshon commit Merge branch 'lt/diff-stat-show-0-lines' (a4eab8f)
   1#!tcsh
   2#
   3# tcsh completion support for core Git.
   4#
   5# Copyright (C) 2012 Marc Khouzam <marc.khouzam@gmail.com>
   6# Distributed under the GNU General Public License, version 2.0.
   7#
   8# When sourced, this script will generate a new script that uses
   9# the git-completion.bash script provided by core Git.  This new
  10# script can be used by tcsh to perform git completion.
  11# The current script also issues the necessary tcsh 'complete'
  12# commands.
  13#
  14# To use this completion script:
  15#
  16#    1) Copy both this file and the bash completion script to ${HOME}.
  17#       You _must_ use the name ${HOME}/.git-completion.bash for the
  18#       bash script.
  19#       (e.g. ~/.git-completion.tcsh and ~/.git-completion.bash).
  20#    2) Add the following line to your .tcshrc/.cshrc:
  21#        source ~/.git-completion.tcsh
  22
  23set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
  24set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
  25
  26# Check that the user put the script in the right place
  27if ( ! -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
  30endif
  31
  32cat << EOF > ${__git_tcsh_completion_script}
  33#!bash
  34#
  35# This script is GENERATED and will be overwritten automatically.
  36# Do not modify it directly.  Instead, modify the git-completion.tcsh
  37# script provided by Git core.
  38#
  39
  40source ${__git_tcsh_completion_original_script}
  41
  42# Set COMP_WORDS in a way that can be handled by the bash script.
  43COMP_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.
  49if [ "\${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[@]}
  53else
  54       # The last character is not a space, so our location is on the
  55       # last word of the command-line array, so we must decrement the
  56       # count by 1
  57       COMP_CWORD=\$((\${#COMP_WORDS[@]}-1))
  58fi
  59
  60# Call _git() or _gitk() of the bash script, based on the first argument
  61_\${1}
  62
  63IFS=\$'\n'
  64echo "\${COMPREPLY[*]}" | sort | uniq
  65EOF
  66
  67complete git  'p/*/`bash ${__git_tcsh_completion_script} git "${COMMAND_LINE}"`/'
  68complete gitk 'p/*/`bash ${__git_tcsh_completion_script} gitk "${COMMAND_LINE}"`/'