Skip to content

Instantly share code, notes, and snippets.

@wancw
Last active September 11, 2018 13:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wancw/e63c7a60e8fe4ef886b3 to your computer and use it in GitHub Desktop.
Save wancw/e63c7a60e8fe4ef886b3 to your computer and use it in GitHub Desktop.
#!/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