1 # ------------------------------------------------------------------------------
2 # FILE: gnu-utils.plugin.zsh
3 # DESCRIPTION: oh-my-zsh plugin file.
4 # AUTHOR: Sorin Ionescu (sorin.ionescu@gmail.com)
6 # ------------------------------------------------------------------------------
8 # Detect if GNU coreutils are installed by looking for gwhoami
9 if [[ ! -x "${commands[gwhoami]}" ]]; then
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'
33 gcmds+=('gfind' 'gxargs' 'glocate')
35 # Not part of either coreutils or findutils, installed separately.
36 gcmds+=('gsed' 'gtar' 'gtime' 'gmake' 'ggrep')
38 # can be built optionally
41 for gcmd in "${gcmds[@]}"; do
42 # Do nothing if the command isn't found
43 (( ${+commands[$gcmd]} )) || continue
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.
50 hash ${gcmd[2,-1]}=${commands[$gcmd]}
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
62 autoload -Uz add-zsh-hook
63 add-zsh-hook preexec __gnu_utils_preexec