aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2022-01-15 10:54:40 +0800
committerAaron LI <aly@aaronly.me>2023-06-13 10:01:03 +0800
commit07a7bab4bd2d3ae4a6e96528b1f1db65d0aadbc8 (patch)
tree50c5c48d3a1f55ee56415d9274483af5714b64a4
parent8e94814d0708d312293e94e6a35f4b5ad555c263 (diff)
downloaddotfiles-07a7bab4bd2d3ae4a6e96528b1f1db65d0aadbc8.tar.bz2
zsh: Add cpatch()/cdiff() for colorizing patch/diff
-rw-r--r--_zshrc12
1 files changed, 12 insertions, 0 deletions
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
#