Skip to content

Instantly share code, notes, and snippets.

@844196
Last active August 29, 2015 14:10
Show Gist options
  • Save 844196/e54f4c3a3d05ef8f8437 to your computer and use it in GitHub Desktop.
Save 844196/e54f4c3a3d05ef8f8437 to your computer and use it in GitHub Desktop.
_git_alias() {
if `git status >/dev/null 2>&1`; then
command=${1}
shift
git ${command} "$@"
if [ "${command}" = 'status' ]; then :; else echo ''; git status; fi
return 0
else
echo "_git_alias: Not a git repository" 1>&2
return 1
fi
}
_git_alias_B() {
if `git status >/dev/null 2>&1`; then
if `which peco >/dev/null 2>&1`; then
alias -g B='`git branch | peco | head -n 1 | sed -e "s/^\*\s//g"`'
else
unalias \B >/dev/null 2>&1
fi
else
unalias \B >/dev/null 2>&1
fi
}
add-zsh-hook precmd _git_alias_B
alias st='_git_alias status'
alias ck='_git_alias checkout'
alias br='_git_alias branch'
alias co='_git_alias commit'
alias mr='_git_alias merge'
alias pu='_git_alias push'
alias di='_git_alias diff'
alias rb='_git_alias rebase'
alias gg='_git_alias graph'
alias lg='_git_alias logg'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment