Merge branch 'mk/tcsh-complete-only-known-paths'
authorJunio C Hamano <gitster@pobox.com>
Fri, 8 Feb 2013 23:28:51 +0000 (15:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Feb 2013 23:28:51 +0000 (15:28 -0800)
The "complete with known paths only" update to completion scripts
returns directory names without trailing slash to compensate the
addition of '/' done by bash that reads from our completion result.
tcsh completion code that reads from our internal completion result
does not add '/', so let it ask our complletion code to keep the '/'
at the end.

* mk/tcsh-complete-only-known-paths:
completion: handle path completion and colon for tcsh script

1  2 
contrib/completion/git-completion.tcsh
index 3e3889f2b4fd3acb441e56284750cb22fef80547,7d17dcd2aa19623b2f4bea32d785133e37121dba..eaacaf0c3e5c63967163f863ec8cd37c01f3e996
@@@ -13,7 -13,6 +13,7 @@@
  #
  # To use this completion script:
  #
 +#    0) You need tcsh 6.16.00 or newer.
  #    1) Copy both this file and the bash completion script to ${HOME}.
  #       You _must_ use the name ${HOME}/.git-completion.bash for the
  #       bash script.
  #        set autolist=ambiguous
  #       It will tell tcsh to list the possible completion choices.
  
 +set __git_tcsh_completion_version = `\echo ${tcsh} | \sed 's/\./ /g'`
 +if ( ${__git_tcsh_completion_version[1]} < 6 || \
 +     ( ${__git_tcsh_completion_version[1]} == 6 && \
 +       ${__git_tcsh_completion_version[2]} < 16 ) ) then
 +      echo "git-completion.tcsh: Your version of tcsh is too old, you need version 6.16.00 or newer.  Git completion will not work."
 +      exit
 +endif
 +unset __git_tcsh_completion_version
 +
  set __git_tcsh_completion_original_script = ${HOME}/.git-completion.bash
  set __git_tcsh_completion_script = ${HOME}/.git-completion.tcsh.bash
  
@@@ -52,6 -42,18 +52,18 @@@ cat << EOF > ${__git_tcsh_completion_sc
  
  source ${__git_tcsh_completion_original_script}
  
+ # Remove the colon as a completion separator because tcsh cannot handle it
+ COMP_WORDBREAKS=\${COMP_WORDBREAKS//:}
+ # For file completion, tcsh needs the '/' to be appended to directories.
+ # By default, the bash script does not do that.
+ # We can achieve this by using the below compatibility
+ # method of the git-completion.bash script.
+ __git_index_file_list_filter ()
+ {
+       __git_index_file_list_filter_compat
+ }
  # Set COMP_WORDS in a way that can be handled by the bash script.
  COMP_WORDS=(\$2)
  
@@@ -74,7 -76,9 +86,7 @@@ f
  _\${1}
  
  IFS=\$'\n'
 -if [ \${#COMPREPLY[*]} -gt 0 ]; then
 -      echo "\${COMPREPLY[*]}" | sort | uniq
 -else
 +if [ \${#COMPREPLY[*]} -eq 0 ]; then
        # No completions suggested.  In this case, we want tcsh to perform
        # standard file completion.  However, there does not seem to be way
        # to tell tcsh to do that.  To help the user, we try to simulate
                # We don't support ~ expansion: too tricky.
                if [ "\${TO_COMPLETE:0:1}" != "~" ]; then
                        # Use ls so as to add the '/' at the end of directories.
 -                      RESULT=(\`ls -dp \${TO_COMPLETE}* 2> /dev/null\`)
 -                      echo \${RESULT[*]}
 -
 -                      # If there is a single completion and it is a directory,
 -                      # we output it a second time to trick tcsh into not adding a space
 -                      # after it.
 -                      if [ \${#RESULT[*]} -eq 1 ] && [ "\${RESULT[0]: -1}" == "/" ]; then
 -                              echo \${RESULT[*]}
 -                      fi
 +                      COMPREPLY=(\`ls -dp \${TO_COMPLETE}* 2> /dev/null\`)
                fi
        fi
  fi
  
 +# tcsh does not automatically remove duplicates, so we do it ourselves
 +echo "\${COMPREPLY[*]}" | sort | uniq
 +
 +# If there is a single completion and it is a directory, we output it
 +# a second time to trick tcsh into not adding a space after it.
 +if [ \${#COMPREPLY[*]} -eq 1 ] && [ "\${COMPREPLY[0]: -1}" == "/" ]; then
 +      echo "\${COMPREPLY[*]}"
 +fi
 +
  EOF
  
  # Don't need this variable anymore, so don't pollute the users environment