From 07a7bab4bd2d3ae4a6e96528b1f1db65d0aadbc8 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 15 Jan 2022 10:54:40 +0800 Subject: zsh: Add cpatch()/cdiff() for colorizing patch/diff --- _zshrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/_zshrc b/_zshrc index 0a27cc7..ca2af45 100644 --- a/_zshrc +++ b/_zshrc @@ -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 # -- cgit v1.2.2