Skip to content

Instantly share code, notes, and snippets.

@eagleas
Created March 15, 2013 13:29
Show Gist options
  • Save eagleas/5169865 to your computer and use it in GitHub Desktop.
Save eagleas/5169865 to your computer and use it in GitHub Desktop.
.bash_aliases with git shortcuts
HISTSIZE=10000
export HISTSIZE
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
source /etc/bash_completion.d/git
export PS1='[\u@\h:\w $(__git_ps1 "(%s)")]\$ '
__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 () {
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 ga add
__git_shortcut gb branch
__git_shortcut gba branch -a
__git_shortcut gc commit '-v -m'
__git_shortcut gca commit '-a -v -m'
__git_shortcut gco checkout
__git_shortcut gd diff
__git_shortcut gdc diff --cached
__git_shortcut gds diff --stat
__git_shortcut gf flow
__git_shortcut gl log
__git_shortcut glp log -p
__git_shortcut gls log --stat
__git_shortcut gs status
__git_shortcut gull pull
__git_shortcut gsub submodule
__git_shortcut gush push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment