Skip to content

Instantly share code, notes, and snippets.

@ajlai
Created February 13, 2012 23:34
Show Gist options
  • Save ajlai/1821466 to your computer and use it in GitHub Desktop.
Save ajlai/1821466 to your computer and use it in GitHub Desktop.
.git_completions
# Working with Mac OS X 10.7, bash 1.3 (brew), git 1.7.4.4 (brew)
# To get this to work, add a line to source it from your ~/.bashrc
# Credit to Scott Bronson for the following tab completion workaround.
# https://github.com/bronson/dotfiles/blob/731bfd951be68f395247982ba1fb745fbed2455c/.bashrc#L81
# (only for bash, zsh tab completions are done separately.)
__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
local cur words cword prev
_get_comp_words_by_ref -n =: cur words cword prev
_git_$2
}
"
}
__git_shortcut () {
alias $1="git $2 $3"
if [[ $SHELL == "/bin/bash" ]]; then
type _git_$2_shortcut &>/dev/null || __define_git_completion $1 $2
complete -o default -o nospace -F _git_$2_shortcut $1
fi
}
__git_shortcut gco checkout
__git_shortcut gad add
__git_shortcut grm rm
__git_shortcut gdi diff
__git_shortcut gcl clone
__git_shortcut gcp cherry-pick -x
__git_shortcut gpl pull
__git_shortcut gpu push
__git_shortcut gbr branch
__git_shortcut gci commit
__git_shortcut gst status
__git_shortcut gl log "-1 --pretty=%h"
__git_shortcut glol log "--graph --decorate --pretty=oneline --abbrev-commit"
__git_shortcut glola log "--graph --decorate --pretty=oneline --abbrev-commit --all"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment