Created
February 20, 2012 07:07
-
-
Save andrewplummer/1868213 to your computer and use it in GitHub Desktop.
Git bash aliases with tab completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Git related aliases | |
| parse_git_branch() { | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
| } | |
| __define_git_completion () { | |
| eval " | |
| _git_$2_shortcut () { | |
| COMP_LINE=\"git $2\${COMP_LINE#$1}\" | |
| let COMP_POINT+=$((4+${#2}-${#1})) | |
| COMP_WORDS=(git $2 \"\${COMP_WORDS[@]:1}\") | |
| let COMP_CWORD+=1 | |
| # Latest bash complete is choking on this... | |
| #_get_comp_words_by_ref -n =: cur words cword prev | |
| local cur words cword prev | |
| _git_$2 | |
| } | |
| " | |
| } | |
| __git_shortcut () { | |
| type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2 | |
| alias $1="git $2 $3" | |
| complete -o default -o nospace -F _git_$2_shortcut $1 | |
| } | |
| __git_shortcut a add | |
| __git_shortcut b branch | |
| __git_shortcut ba branch -a | |
| __git_shortcut co checkout | |
| __git_shortcut c commit | |
| __git_shortcut ci commit -a | |
| __git_shortcut d diff | |
| __git_shortcut dc diff --cached | |
| __git_shortcut ds diff --stat | |
| __git_shortcut f fetch | |
| __git_shortcut up push origin | |
| # Custom logging | |
| __git_shortcut l prettylog | |
| __git_shortcut g prettygraph | |
| alias s='git status' # no completion for git status | |
| alias ff='git ff' # no completion for fast-forward |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment