-
-
Save kohenkatz/2313082 to your computer and use it in GitHub Desktop.
# Source this script in tcsh to setup shell completions | |
# for git. Completions are activated by typing or Control-D | |
# in the shell after entering a partial command. | |
# | |
# Usage: | |
# source git-completion.tcsh (e.g. in ~/.cshrc) | |
# | |
# Supported completions: | |
# git (lists git commands) | |
# git help (lists git commands) | |
# git branch (lists branch names) | |
# git checkout (lists branch names) | |
# git log (lists the most commonly used flags) | |
# git remote (lists git remote commands) | |
# git remote add|prune|rm|show|update | |
# (lists git remote names) | |
# In addition to entering where shown, you can enter it after | |
# typing part of the word, e.g. git branch bug to auto-complete | |
# branches starting with "bug". | |
# | |
# Author: David Adler, David Aguilar | |
# Note: you will likely have to change this path to point to your Git installation. | |
# You can also try to use "which git" to autodetect whether Git is installed. | |
if ( -x ~/bin/git) then | |
# Git is installed so define tcsh completions for it. | |
# List of known git subcommands | |
# This is a hard-coded list to avoid calling 'git help' at startup. | |
set __git_cmd_names = (add bisect blame branch checkout clone commit config \ | |
diff diff-files difftool fetch grep gui init log merge mv pull push \ | |
rebase reset rm show shortlog stash status tag) | |
alias __git_aliases 'git config --get-regexp "alias.*" | sed -n "s,alias\.\([^ ]*\).*,\1,p"' | |
alias __git_branches 'git for-each-ref –format="%(refname)" refs/heads refs/remotes | sed -e s,refs/remotes/,, | sed -e s,refs/heads/,,' | |
alias __git_origin_branches 'git for-each-ref –format="%(refname)" refs/remotes/origin | grep -v HEAD | sed -e s,refs/remotes/origin/,,' | |
# Define the completions (see the tcsh man page). | |
complete git \ | |
'p/1/`__git_aliases | xargs echo $__git_cmd_names`/' \ | |
"n/help/($__git_cmd_names)/" \ | |
'n/branch/`__git_branches | xargs echo -m -d`/' \ | |
'n/config/(–global –get-regexp –list)/' \ | |
'n/diff/`__git_branches | xargs echo –check –staged –stat -- *`/' \ | |
'n/difftool/`__git_branches | xargs echo –no-prompt –staged -- *`/' \ | |
'n/fetch/`git remote`/' \ | |
'n/merge/`__git_branches`/' \ | |
'n/log/`__git_branches | xargs echo -- –name-only –name-status –reverse –committer= –no-color –relative –ignore-space-change –ignore-space-at-eol –format=medium –format=full –format=fuller`/' \ | |
'n/stash/(apply list save pop clear)/' \ | |
'n/push/`git remote`/' \ | |
'N/push/`__git_origin_branches`/' \ | |
'n/pull/`git remote | xargs echo –rebase`/' \ | |
'n/–rebase/`git remote`/' \ | |
'N/–rebase/`__git_origin_branches`/' \ | |
'N/pull/`__git_origin_branches`/' \ | |
'n/rebase/`__git_branches | xargs echo –continue –abort –onto –skip –interactive`/' \ | |
'N/rebase/`__git_branches`/' \ | |
'n/remote/(show add rm prune update)/' \ | |
'N/remote/`git remote`/' \ | |
'n/checkout/`__git_branches | xargs echo -b –`/' \ | |
'N/-b/`__git_branches`/' | |
endif |
@dbu I should have written a note about that. However, since my sysadmin refuses to install Git, I (and others who I work with) use Git in the home directory. You're welcome to fork the gist and change it but I am going to leave it because this is how I use it.
you could use
which git >& /dev/null
if ( ! $status) then
endif
Something is messy with some doucle dash (--) sequences, when downloading the raw file, there are some non-ascii characters there: 0xe2 0x80 0x93.
Note that git 1.8.1 will have a first version of support for tcsh-completion as mentioned below:
http://marc.info/?l=git&m=135456897811682&w=2
You can find the script, git-completion.tcsh, and the necessary accompanying bash script, git-completion.bash, here:
https://github.com/git/git/tree/master/contrib/completion
Some improvements are still being worked on.
Marc
note that usually people have git installed at /usr/bin/git , not in their home directory. edit the "if (-x" line at the start of the script to make this actually work.