Last active
September 11, 2018 13:03
-
-
Save wancw/e63c7a60e8fe4ef886b3 to your computer and use it in GitHub Desktop.
Git Diff Prettifier, adapted from https://github.com/paulirish/dotfiles/commit/6743b907ff586c28cd36e08d1e1c634e2968893e
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
#!/usr/bin/env zsh | |
# Copied from https://github.com/paulirish/dotfiles/commit/6743b907ff586c28cd36e08d1e1c634e2968893e | |
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 -E "s/^($color_code_regex)diff --git .*$//g" | \ | |
sed -E "s/^($color_code_regex)index .*$/\ | |
\1$(rule)/g" | \ | |
sed -E "s/^($color_code_regex)\+\+\+(.*)$/\1\+\+\+\5\\ | |
\1$(rule)/g" | \ | |
# actually strips the leading symbols | |
sed -E "s/^($color_code_regex)[\+\-]/\1 /g" | |
} | |
## Print a horizontal rule | |
rule () { | |
printf "%$(tput cols)s\n"|tr " " "─" | |
} | |
/usr/local/share/git-core/contrib/diff-highlight/diff-highlight | strip_diff_leading_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment