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