e5af22cca6a07c9be52fe48810faaa08261e4d15

Author
Mark Mercado <mamercad@gmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

feat(plugins): add grc plugin for Generic Colouriser (#9315)

Co-authored-by: Marc Cornellà <marc.cornella@live.com>

Diff

 1diff --git a/plugins/grc/README.md b/plugins/grc/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..dfda414664df8c42dfe9b8ec4ff22136a310129c
 4--- /dev/null
 5+++ b/plugins/grc/README.md
 6@@ -0,0 +1,37 @@
 7+# Generic Colouriser plugin
 8+
 9+This plugin adds wrappers for commands supported by [Generic Colouriser](https://github.com/garabik/grc):
10+
11+To use it, add `grc` to the plugins array in your zshrc file:
12+
13+```zsh
14+plugins=(... grc)
15+```
16+
17+## Commands
18+
19+The following commands are wrapped by `grc` so that their output is automatically colored:
20+
21+- `cc`
22+- `configure`
23+- `cvs`
24+- `df`
25+- `diff`
26+- `dig`
27+- `gcc`
28+- `gmake`
29+- `ifconfig`
30+- `iwconfig`
31+- `last`
32+- `ldap`
33+- `make`
34+- `mount`
35+- `mtr`
36+- `netstat`
37+- `ping`
38+- `ping6`
39+- `ps`
40+- `traceroute`
41+- `traceroute6`
42+- `wdiff`
43+- `whois`
44diff --git a/plugins/grc/grc.plugin.zsh b/plugins/grc/grc.plugin.zsh
45new file mode 100644
46index 0000000000000000000000000000000000000000..6a52ec56865ffc90614dea36dd2953b588465e62
47--- /dev/null
48+++ b/plugins/grc/grc.plugin.zsh
49@@ -0,0 +1,44 @@
50+# Adapted from: https://github.com/garabik/grc/blob/master/grc.zsh
51+
52+if [[ "$TERM" = dumb ]] || (( ! $+commands[grc] )); then
53+  return
54+fi
55+
56+# Supported commands
57+cmds=(
58+  cc
59+  configure
60+  cvs
61+  df
62+  diff
63+  dig
64+  gcc
65+  gmake
66+  ifconfig
67+  iwconfig
68+  last
69+  ldap
70+  make
71+  mount
72+  mtr
73+  netstat
74+  ping
75+  ping6
76+  ps
77+  traceroute
78+  traceroute6
79+  wdiff
80+  whois
81+)
82+
83+# Set alias for supported commands
84+for cmd in $cmds; do
85+  if (( $+commands[$cmd] )); then
86+    eval "function $cmd {
87+      grc --colour=auto \"${commands[$cmd]}\" \"\$@\"
88+    }"
89+  fi
90+done
91+
92+# Clean up variables
93+unset cmds cmd