]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/gnu-utils/gnu-utils.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-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 # Detect if GNU coreutils are installed by looking for gwhoami
9 if [[ ! -x "${commands[gwhoami]}" ]]; then
10   return
11 fi
12
13 __gnu_utils() {
14   local -a gcmds
15   local gcmd
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   # findutils
33   gcmds+=('gfind' 'gxargs' 'glocate')
34
35   # Not part of either coreutils or findutils, installed separately.
36   gcmds+=('gsed' 'gtar' 'gtime' 'gmake' 'ggrep')
37
38   # can be built optionally
39   gcmds+=('ghostname')
40
41   for gcmd in "${gcmds[@]}"; do
42     # Do nothing if the command isn't found
43     (( ${+commands[$gcmd]} )) || continue
44     
45     # This method allows for builtin commands to be primary but it's
46     # lost if hash -r or rehash is executed, or if $PATH is updated.
47     # Thus, a preexec hook is needed, which will only run if whoami
48     # is not already rehashed.
49     #
50     hash ${gcmd[2,-1]}=${commands[$gcmd]}
51   done
52
53   return 0
54 }
55
56 __gnu_utils_preexec() {
57   # Run __gnu_utils when the whoami command is not already rehashed.
58   # This acts as a sign that we need to rehash all GNU utils.
59   [[ "${commands[whoami]}" = "${commands[gwhoami]}" ]] || __gnu_utils
60 }
61
62 autoload -Uz add-zsh-hook
63 add-zsh-hook preexec __gnu_utils_preexec