diff options
author | Aaron LI <aly@aaronly.me> | 2022-01-15 10:54:40 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2023-06-13 10:01:03 +0800 |
commit | 07a7bab4bd2d3ae4a6e96528b1f1db65d0aadbc8 (patch) | |
tree | 50c5c48d3a1f55ee56415d9274483af5714b64a4 | |
parent | 8e94814d0708d312293e94e6a35f4b5ad555c263 (diff) | |
download | dotfiles-07a7bab4bd2d3ae4a6e96528b1f1db65d0aadbc8.tar.bz2 |
zsh: Add cpatch()/cdiff() for colorizing patch/diff
-rw-r--r-- | _zshrc | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -240,6 +240,18 @@ dec2ip() { printf '%d.%d.%d.%d' $(echo "obase=256; $1" | bc) } +## Colorize patch / diff output +# Credit: https://www.moritz.systems/bsd-tips-and-tricks/show-diff-output-in-color/ +cpatch() { + local _c1="$(tput setaf 1)$(tput bold)" # red bold + local _c2="$(tput setaf 2)$(tput bold)" # green bold + local _clr=$(tput sgr0) + sed -e 's/^-.*$/'${_c1}'&'${_clr}'/' -e 's/^+.*$/'${_c2}'&'${_clr}'/' +} +cdiff() { + diff -u "$@" | cpatch +} + # # Terminal settings # |