zpm-zsh / colorize Goto Github PK
View Code? Open in Web Editor NEWColorize the output of various programs
License: GNU General Public License v3.0
Colorize the output of various programs
License: GNU General Public License v3.0
if (( $+commands[diff-so-fancy] )); then
function diff() {
command diff "$@" | diff-so-fancy
}
elif (( $+commands[delta] )); then
function diff() {
command diff "$@" | delta
}
else
function diff() {
command diff --color "$@"
}
fi
In fact, if user installed delta,
❯ echo a > a
❯ echo b > b
❯ command diff a b
1c1
< a
---
> b
❯ command diff a b | delta
1c1
< a
---
> b
❯ command diff -u a b
--- a 2021-08-30 17:24:50.801599241 +0800
+++ b 2021-08-30 17:24:53.541625220 +0800
@@ -1 +1 @@
-a
+b
❯ command diff -u a b|delta
comparing: a ⟶ b
─────────────────────────────────────────
──────┐
Δ :1: │
──────┘
│ 1 │a │ │
│ │ │ 1 │b
❯ delta a b
comparing: a ⟶ b
─────────────────────────────────────────
──────┐
Δ :1: │
──────┘
│ 1 │a │ │
│ │ │ 1 │b
command diff a b|delta
is same as command diff a b
.
So it is unnecessary to add this function.
For
function diff() {
command diff -u "$@" | delta
}
I think it is unnecessary, too. Because delta a b
is same, it just like
alias diff=delta
So, I think
function diff() {
command diff --color "$@"
}
is enough for everyone.
PS: in man diff
--color[=WHEN]
color output; WHEN is 'never', 'always', or 'auto'; plain --color means --color='auto'
❯ ip a
Option "-color=auto" is unknown, try "ip -help".
❯ declare -f ip
ip () {
command ip --color=auto "$@"
}
❯ command ip -help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
vrf | sr }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}
❯ command ip -c a
# output with color
❯ command ip -V
ip utility, iproute2-ss171113
Another device:
❯ ip a
# output with color
❯ command ip -c a
# output with color
❯ ip -V
ip utility, iproute2-5.13.0
❯ ip -h
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { address | addrlabel | fou | help | ila | l2tp | link |
macsec | maddress | monitor | mptcp | mroute | mrule |
neighbor | neighbour | netconf | netns | nexthop | ntable |
ntbl | route | rule | sr | tap | tcpmetrics |
token | tunnel | tuntap | vrf | xfrm }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec | -j[son] | -p[retty] |
-f[amily] { inet | inet6 | mpls | bridge | link } |
-4 | -6 | -I | -D | -M | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | -n[etns] name | -N[umeric] | -a[ll] |
-c[olor]}
How about
diff --git a/colorize.plugin.zsh b/colorize.plugin.zsh
index 85fa38b..289511a 100644
--- a/colorize.plugin.zsh
+++ b/colorize.plugin.zsh
@@ -14,7 +14,7 @@ DEPENDENCES_DEBIAN+=( grc )
export LESS="$LESS -R -M"
function ip() {
- command ip --color=auto "$@"
+ command ip -color "$@"
}
function grep() {
I test it can solve this bug.
Thanks!
Since the last update, various commands (eg du) fail and abort with this message: maximum nested function level reached using macos 10.14.6, zsh 5.8 (x86_64-apple-darwin18.7.0) and zinit. How can I solve this? Thanks!
When LESS environment is already set, it gets overwritten by this plugin. This can potentially lead to undesired behavior on other applications.
Example: if user has already set LESS environment variable to avoid git command from paging when it's not necessary:
❯ echo $LESS
-F -X -R
after invoking this plugin, LESS environment becomes:
❯ echo $LESS
-R -M
Now git behavior is to page even when not needed.
Steps to reproduce:
diff . /
Expected results:
a list of files
Actual results:
An error message:
diff: unrecognized option `--color'
diff: Try `diff --help' for more information.
I keep getting an error from env
saying
➜ env
env: invalid option -- 'h'
Try 'env --help' for more information.
I'm not sure why the -h
flag is invoked in this plugin. Perhaps you could shed some light on that? Otherwise I'm pretty sure it doesn't need to be there.
Edit: I can confirm that removing the -h
flag doesn't appear to change anything. Output is still colorized.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.