Return 1 when GNU Core Utilities are not found

This commit is contained in:
Sorin Ionescu 2012-03-28 12:23:02 -04:00
parent 647ac1ac00
commit 9155aea2db

View File

@ -5,70 +5,73 @@
# Sorin Ionescu <sorin.ionescu@gmail.com> # Sorin Ionescu <sorin.ionescu@gmail.com>
# #
if (( $+commands[gdircolors] )); then # Check for the presence of GNU Core Utilities.
function __gnu_utils { if (( ! $+commands[gdircolors] )); then
emulate -L zsh return 1
local gcmds fi
local gcmd
local cmd function __gnu_utils {
local prefix emulate -L zsh
local gcmds
# GNU Coreutils. local gcmd
gcmds=('g[' 'gbase64' 'gbasename' 'gcat' 'gchcon' 'gchgrp' 'gchmod' local cmd
'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate' local prefix
'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand'
'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid' # GNU Coreutils.
'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum' gcmds=('g[' 'gbase64' 'gbasename' 'gcat' 'gchcon' 'gchgrp' 'gchmod'
'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc' 'gchown' 'gchroot' 'gcksum' 'gcomm' 'gcp' 'gcsplit' 'gcut' 'gdate'
'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd' 'gdd' 'gdf' 'gdir' 'gdircolors' 'gdirname' 'gdu' 'gecho' 'genv' 'gexpand'
'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum' 'gexpr' 'gfactor' 'gfalse' 'gfmt' 'gfold' 'ggroups' 'ghead' 'ghostid'
'gsha256sum' 'gsha384sum' 'gsha512sum' 'gshred' 'gshuf' 'gsleep' 'gsort' 'gid' 'ginstall' 'gjoin' 'gkill' 'glink' 'gln' 'glogname' 'gls' 'gmd5sum'
'gsplit' 'gstat' 'gstty' 'gsum' 'gsync' 'gtac' 'gtail' 'gtee' 'gtest' 'gmkdir' 'gmkfifo' 'gmknod' 'gmktemp' 'gmv' 'gnice' 'gnl' 'gnohup' 'gnproc'
'gtimeout' 'gtouch' 'gtr' 'gtrue' 'gtruncate' 'gtsort' 'gtty' 'guname' 'god' 'gpaste' 'gpathchk' 'gpinky' 'gpr' 'gprintenv' 'gprintf' 'gptx' 'gpwd'
'gunexpand' 'guniq' 'gunlink' 'guptime' 'gusers' 'gvdir' 'gwc' 'gwho' 'greadlink' 'grm' 'grmdir' 'gruncon' 'gseq' 'gsha1sum' 'gsha224sum'
'gwhoami' 'gyes') 'gsha256sum' 'gsha384sum' 'gsha512sum' 'gshred' 'gshuf' 'gsleep' 'gsort'
'gsplit' 'gstat' 'gstty' 'gsum' 'gsync' 'gtac' 'gtail' 'gtee' 'gtest'
# Not part of coreutils, installed separately. 'gtimeout' 'gtouch' 'gtr' 'gtrue' 'gtruncate' 'gtsort' 'gtty' 'guname'
gcmds+=('ggrep' 'gsed' 'gtar' 'gtime') 'gunexpand' 'guniq' 'gunlink' 'guptime' 'gusers' 'gvdir' 'gwc' 'gwho'
'gwhoami' 'gyes')
for gcmd in "$gcmds[@]"; do
# # Not part of coreutils, installed separately.
# This method allows for builtin commands to be primary but it's gcmds+=('ggrep' 'gsed' 'gtar' 'gtime')
# lost if hash -r or rehash -f is executed. Thus, those two
# functions have to be wrapped. for gcmd in "$gcmds[@]"; do
# #
if (( $+commands[$gcmd] )); then # This method allows for builtin commands to be primary but it's
hash "$gcmd[2,-1]"="$commands[$gcmd]" # lost if hash -r or rehash -f is executed. Thus, those two
fi # functions have to be wrapped.
done #
if (( $+commands[$gcmd] )); then
return 0 hash "$gcmd[2,-1]"="$commands[$gcmd]"
} fi
__gnu_utils; done
function hash { return 0
if (( $+argv[(er)-r] )) || (( $+argv[(er)-f] )); then }
builtin hash "$@" __gnu_utils;
__gnu_utils
else function hash {
builtin hash "$@" if (( $+argv[(er)-r] )) || (( $+argv[(er)-f] )); then
fi builtin hash "$@"
} __gnu_utils
else
function rehash { builtin hash "$@"
hash -r "$@" fi
} }
# A sensible default for ls. function rehash {
alias ls='ls --group-directories-first' hash -r "$@"
}
if zstyle -t ':omz:alias:ls' color; then
if [[ -f "$HOME/.dir_colors" ]]; then # A sensible default for ls.
eval $(gdircolors "$HOME/.dir_colors") alias ls='ls --group-directories-first'
fi
alias ls="$aliases[ls] --color=auto" if zstyle -t ':omz:alias:ls' color; then
else if [[ -f "$HOME/.dir_colors" ]]; then
alias ls="$aliases[ls] -F" eval $(gdircolors "$HOME/.dir_colors")
fi fi
alias ls="$aliases[ls] --color=auto"
else
alias ls="$aliases[ls] -F"
fi fi