bf86502b6940d938c488254befdf9461cb50591b

Author
Sorin Ionescu <sorin.ionescu@gmail.com>
Committer
Sorin Ionescu <sorin.ionescu@gmail.com>
Date

Message

Added gnu-utils plugin.

Diff

 1diff --git a/plugins/gnu-utils/gnu-utils.plugin.zsh b/plugins/gnu-utils/gnu-utils.plugin.zsh
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..e59265d664fa6f0022c52d2791bcf78a84d2b793
 4--- /dev/null
 5+++ b/plugins/gnu-utils/gnu-utils.plugin.zsh
 6@@ -0,0 +1,80 @@
 7+# ------------------------------------------------------------------------------
 8+#          FILE:  gnu-utils.plugin.zsh
 9+#   DESCRIPTION:  oh-my-zsh plugin file.
10+#        AUTHOR:  Sorin Ionescu (sorin.ionescu@gmail.com)
11+#       VERSION:  1.0.0
12+# ------------------------------------------------------------------------------
13+
14+
15+if [[ -x "${commands[gwhoami]}" ]]; then 
16+  __gnu_utils() {
17+    emulate -L zsh
18+    local gcmds
19+    local gcmd
20+    local cmd
21+    local prefix
22+
23+    # coreutils 
24+    gcmds=('g[' 'gbase64' 'gbasename' 'gcat' 'gchcon' 'gchgrp' 'gchmod'
25+    'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate'
26+    'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand'
27+    'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid'
28+    'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum'
29+    'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc'
30+    'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd'
31+    'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum'
32+    'gsha256sum' 'gsha384sum' 'gsha512sum' 'gshred' 'gshuf' 'gsleep' 'gsort'
33+    'gsplit' 'gstat' 'gstty' 'gsum' 'gsync' 'gtac' 'gtail' 'gtee' 'gtest'
34+    'gtimeout' 'gtouch' 'gtr' 'gtrue' 'gtruncate' 'gtsort' 'gtty' 'guname'
35+    'gunexpand' 'guniq' 'gunlink' 'guptime' 'gusers' 'gvdir' 'gwc' 'gwho'
36+    'gwhoami' 'gyes')
37+
38+    # Not part of coreutils, installed separately.
39+    gcmds+=('gsed' 'gtar' 'gtime')
40+
41+    for gcmd in "${gcmds[@]}"; do
42+      #
43+      # This method allows for builtin commands to be primary but it's
44+      # lost if hash -r or rehash -f is executed. Thus, those two 
45+      # functions have to be wrapped.
46+      #
47+      (( ${+commands[$gcmd]} )) && hash ${gcmd[2,-1]}=${commands[$gcmd]}
48+
49+      #
50+      # This method generates wrapper functions.
51+      # It will override shell builtins.
52+      #
53+      # (( ${+commands[$gcmd]} )) && \
54+      # eval "function $gcmd[2,-1]() { \"${prefix}/${gcmd//"["/"\\["}\" \"\$@\"; }"
55+
56+      #
57+      # This method is inflexible since the aliases are at risk of being
58+      # overriden resulting in the BSD coreutils being called.
59+      #
60+      # (( ${+commands[$gcmd]} )) && \
61+      # alias "$gcmd[2,-1]"="${prefix}/${gcmd//"["/"\\["}"
62+    done
63+
64+    return 0
65+  }
66+  __gnu_utils;
67+
68+  function hash() {
69+    if [[ "$*" =~ "-(r|f)" ]]; then
70+      builtin hash "$@"
71+      __gnu_utils
72+    else
73+      builtin hash "$@"
74+    fi
75+  }
76+
77+  function rehash() {
78+    if [[ "$*" =~ "-f" ]]; then
79+      builtin rehash "$@"
80+      __gnu_utils
81+    else
82+      builtin rehash "$@"
83+    fi
84+  }
85+fi
86+