From 6743b907ff586c28cd36e08d1e1c634e2968893e Mon Sep 17 00:00:00 2001 From: Paul Irish Date: Sun, 20 Sep 2015 19:46:44 -0700 Subject: [PATCH] far more attractive git diffs. word-highlight and simplified header. http://i.imgur.com/uqp0MHa.png --- .aliases | 1 - .bash_profile | 2 ++ .functions | 16 ++++++++++++++++ .gitconfig | 8 ++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.aliases b/.aliases index 311305b4d2..c6b11f3380 100644 --- a/.aliases +++ b/.aliases @@ -58,7 +58,6 @@ alias undopush="git push -f origin HEAD^:master" alias gr='[ ! -z `git rev-parse --show-cdup` ] && cd `git rev-parse --show-cdup || pwd`' - # IP addresses alias ip="dig +short myip.opendns.com @resolver1.opendns.com" alias localip="ipconfig getifaddr en1" diff --git a/.bash_profile b/.bash_profile index 27e4528690..f326e4633f 100644 --- a/.bash_profile +++ b/.bash_profile @@ -13,6 +13,8 @@ case $- in esac +ln -sf "$(brew --prefix)/share/git-core/contrib/diff-highlight/diff-highlight" ~/bin/diff-highlight + # generic colouriser GRC=`which grc` if [ "$TERM" != dumb ] && [ -n "$GRC" ] diff --git a/.functions b/.functions index 50cbc33410..aac1cd07a5 100644 --- a/.functions +++ b/.functions @@ -55,6 +55,22 @@ function whois() { /usr/bin/whois -h whois.internic.net $domain | sed '/NOTICE:/q' } +function strip_diff_leading_symbols(){ + color_code_regex="(\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K])" + + # simplify the unified patch diff header + sed -r "s/^($color_code_regex)diff --git .*$//g" | \ + sed -r "s/^($color_code_regex)index .*$/\n\1$(rule)/g" | \ + sed -r "s/^($color_code_regex)\+\+\+(.*)$/\1+++\5\n\1$(rule)\x1B\[m/g" |\ + + # actually strips the leading symbols + sed -r "s/^($color_code_regex)[\+\-]/\1 /g" +} + +## Print a horizontal rule +rule () { + printf "%$(tput cols)s\n"|tr " " "─"}} +} # Extract archives - use: extract diff --git a/.gitconfig b/.gitconfig index 88b6c37d1b..146e49af31 100644 --- a/.gitconfig +++ b/.gitconfig @@ -31,6 +31,8 @@ [core] excludesfile = ~/.gitignore attributesfile = ~/.gitattributes + # insanely beautiful diffs + pager = bash -lc 'diff-highlight | strip_diff_leading_symbols | less -r' - [color "branch"] current = yellow reverse local = yellow @@ -48,6 +50,12 @@ tool = opendiff +[color "diff-highlight"] + oldNormal = "red bold" + oldHighlight = "red bold 52" + newNormal = "green bold" + newHighlight = "green bold 22" + # rewrites [url "git@github.com:"] insteadOf = "gh:"