Last active
August 29, 2015 14:18
-
-
Save yonigoldberg/09cefd4a930d3ed39a61 to your computer and use it in GitHub Desktop.
Pimp your git
This file contains 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
#functions for showing git repo status on the command line | |
# * uncommitted changes | |
# ^ stashed changes | |
# > ahead of origin | |
# < behind origin | |
# ↕ diverged from origin | |
# R rebasing | |
function parse_git_dirty() { | |
regex="working directory clean" | |
if [[ $1 =~ $regex ]] | |
then | |
echo "" | |
else | |
echo "*" | |
fi | |
} | |
function parse_git_rebasing() { | |
regex="currently rebasing" | |
if [[ $1 =~ $regex ]] | |
then | |
echo "R" | |
else | |
echo "" | |
fi | |
} | |
function parse_git_stash (){ | |
stash=`git stash list 2> /dev/null | wc -l | tr -d ' '` | |
[[ $stash != 0 ]] && echo "^$stash" | |
} | |
function parse_git_ahead() { | |
regex="Your branch is ahead of [a-z'/]+ by ([0-9]+)" | |
if [[ $1 =~ $regex ]] | |
then | |
n=${BASH_REMATCH[1]} | |
echo ">$n" | |
fi | |
} | |
function parse_git_behind() { | |
regex="Your branch is behind [a-z'/]+ by ([0-9]+)" | |
if [[ $1 =~ $regex ]] | |
then | |
n=${BASH_REMATCH[1]} | |
echo "<$n" | |
fi | |
} | |
function parse_git_diverge() { | |
regex="([0-9]+) and ([0-9]+) different commits" | |
if [[ $1 =~ $regex ]] | |
then | |
your=${BASH_REMATCH[1]} | |
source=${BASH_REMATCH[2]} | |
symbol="↕" | |
echo "$your$symbol$source" | |
fi | |
} | |
function current_git_branch() { | |
git rev-parse --abbrev-ref HEAD 2> /dev/null | |
} | |
function current_git_branch_with_markers { | |
current=`current_git_branch` | |
if [[ $current ]] | |
then | |
git_status=`git status 2> /dev/null` | |
stash=`parse_git_stash` | |
ahead=`parse_git_ahead "$git_status"` | |
behind=`parse_git_behind "$git_status"` | |
diverge=`parse_git_diverge "$git_status"` | |
dirty=`parse_git_dirty "$git_status"` | |
rebasing=`parse_git_rebasing "$git_status"` | |
echo $current | sed -e "s/\(.*\)/ \[\1$ahead$behind$diverge$dirty$rebasing$stash\]/" | |
fi | |
} | |
function set_prompt { | |
local BLACK="\[\033[0;38m\]" | |
local RED="\[\033[0;31m\]" | |
local RED_BOLD="\[\033[01;31m\]" | |
local BLUE="\[\033[01;34m\]" | |
local GREEN="\[\033[0;32m\]" | |
PS1="$RED\h $GREEN\w $RED_BOLD\$(current_git_branch_with_markers) $BLACK\$ " | |
} | |
set_prompt |
This file contains 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
[core] | |
excludesfile = /Users/$USER/.gitignore_global | |
[color] | |
diff = auto | |
branch = auto | |
status = auto | |
[push] | |
default = upstream | |
[alias] | |
st = !git status | |
up = !git fetch --tags & git status | |
ci = !git commit -a | |
df = !git difftool | |
dfc = !git df --cached | |
co = checkout | |
cob = checkout -b | |
lol =log --graph --decorate --pretty=format:\"%Cblue %h%C(magenta) %ad %C(cyan) %d %Creset %s %C(green)[%an]\" --date=short | |
l = log --pretty=format:\"%Cblue%h %C(magenta)%ad %C(green)[%an] %Creset%s %C(cyan)%d\" --date=short | |
author = log --pretty=format:\"%C(blue) %h %C(magenta) %ad %C(green) [%an] %Creset %s\" --date=short --author | |
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs -r git branch -d; }; f" | |
ec = config --global -e | |
up = !git pull --rebase --prune $@ && git submodule update --init --recursive | |
cm = !git add -A && git commit -m | |
save = !git add -A && git commit -m 'SAVEPOINT' | |
undo = reset HEAD~1 --mixed | |
amend = commit -a --amend | |
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard | |
bclean = "!f() { git branch --merged ${1-master} | grep -v " ${1-master}$" | xargs git branch -d; }; f" | |
bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1-master}; }; f" | |
[branch] | |
autosetuprebase = always | |
[pull] | |
rebase = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment