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