2012-01-31 23:37:51 -05:00
|
|
|
#
|
|
|
|
# Provides for the interactive usage of GNU Coreutils on BSD systems.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
2012-04-02 12:00:34 -04:00
|
|
|
|
|
|
|
# Get the prefix or use the default.
|
2012-03-28 12:41:39 -04:00
|
|
|
zstyle -s ':omz:module:gnu-utils' prefix '_gnu_utils_prefix' ||
|
2012-04-02 12:00:34 -04:00
|
|
|
_gnu_utils_prefix='g'
|
2011-02-03 17:25:45 -05:00
|
|
|
|
2012-03-28 12:23:02 -04:00
|
|
|
# Check for the presence of GNU Core Utilities.
|
2012-04-02 12:00:34 -04:00
|
|
|
if (( ! $+commands[${_gnu_utils_prefix}dircolors] )); then
|
2012-03-28 12:23:02 -04:00
|
|
|
return 1
|
|
|
|
fi
|
2011-02-03 17:25:45 -05:00
|
|
|
|
2012-04-02 13:06:26 -04:00
|
|
|
function _gnu-utils-hash-commands {
|
2012-03-28 12:23:02 -04:00
|
|
|
emulate -L zsh
|
2012-04-02 12:00:34 -04:00
|
|
|
|
|
|
|
local cmds
|
2012-03-28 12:23:02 -04:00
|
|
|
local cmd
|
2012-04-02 12:00:34 -04:00
|
|
|
local pcmd
|
2011-02-03 17:25:45 -05:00
|
|
|
|
2012-04-02 12:00:34 -04:00
|
|
|
cmds=(
|
2012-04-02 11:22:30 -04:00
|
|
|
# Coreutils
|
2012-04-02 12:00:34 -04:00
|
|
|
'[' 'base64' 'basename' 'cat' 'chcon' 'chgrp' 'chmod' 'chown'
|
|
|
|
'chroot' 'cksum' 'comm' 'cp' 'csplit' 'cut' 'date' 'dd' 'df'
|
|
|
|
'dir' 'dircolors' 'dirname' 'du' 'echo' 'env' 'expand' 'expr'
|
|
|
|
'factor' 'false' 'fmt' 'fold' 'groups' 'head' 'hostid' 'id'
|
|
|
|
'install' 'join' 'kill' 'link' 'ln' 'logname' 'ls' 'md5sum'
|
|
|
|
'mkdir' 'mkfifo' 'mknod' 'mktemp' 'mv' 'nice' 'nl' 'nohup' 'nproc'
|
|
|
|
'od' 'paste' 'pathchk' 'pinee' 'pr' 'printenv' 'printf' 'ptx'
|
|
|
|
'pwd' 'readlink' 'realpath' 'rm' 'rmdir' 'runcon' 'seq' 'sha1sum'
|
|
|
|
'sha224sum' 'sha256sum' 'sha384sum' 'sha512sum' 'shred' 'shuf'
|
|
|
|
'sleep' 'sort' 'split' 'stat' 'stty' 'sum' 'sync' 'tac' 'tail'
|
|
|
|
'tee' 'test' 'timeout' 'touch' 'tr' 'true' 'truncate' 'tsort'
|
|
|
|
'tty' 'uname' 'unexpand' 'uniq' 'unlink' 'uptime' 'users' 'vdir'
|
|
|
|
'wc' 'who' 'whoami' 'yes'
|
2011-02-03 17:25:45 -05:00
|
|
|
|
2012-04-02 11:22:30 -04:00
|
|
|
# The following are not part of Coreutils but installed separately.
|
|
|
|
|
|
|
|
# Binutils
|
2012-04-02 12:00:34 -04:00
|
|
|
'addr2line' 'ar' 'c++filt' 'elfedit' 'nm' 'objcopy' 'objdump'
|
|
|
|
'ranlib' 'readelf' 'size' 'strings' 'strip'
|
2012-04-02 11:22:30 -04:00
|
|
|
|
|
|
|
# Findutils
|
2012-04-02 12:00:34 -04:00
|
|
|
'find' 'locate' 'oldfind' 'updatedb' 'xargs'
|
2012-04-02 11:22:30 -04:00
|
|
|
|
|
|
|
# Libtool
|
2012-04-02 12:00:34 -04:00
|
|
|
'libtool' 'libtoolize'
|
2012-04-02 11:22:30 -04:00
|
|
|
|
|
|
|
# Miscellaneous
|
2012-04-02 12:00:34 -04:00
|
|
|
'getopt' 'grep' 'indent' 'sed' 'tar' 'time' 'units' 'which'
|
2012-04-02 11:22:30 -04:00
|
|
|
)
|
2011-02-03 17:25:45 -05:00
|
|
|
|
2012-04-02 12:00:34 -04:00
|
|
|
for cmd in "$cmds[@]"; do
|
2012-03-28 12:23:02 -04:00
|
|
|
#
|
|
|
|
# This method allows for builtin commands to be primary but it's
|
|
|
|
# lost if hash -r or rehash -f is executed. Thus, those two
|
|
|
|
# functions have to be wrapped.
|
|
|
|
#
|
2012-04-02 12:00:34 -04:00
|
|
|
pcmd="${_gnu_utils_prefix}${cmd}"
|
|
|
|
if (( $+commands[$pcmd] )); then
|
|
|
|
builtin hash "$cmd"="$commands[$pcmd]"
|
2011-02-03 17:25:45 -05:00
|
|
|
fi
|
2012-03-28 12:23:02 -04:00
|
|
|
done
|
2011-02-03 17:25:45 -05:00
|
|
|
|
2012-03-28 12:23:02 -04:00
|
|
|
return 0
|
|
|
|
}
|
2012-04-02 13:06:26 -04:00
|
|
|
_gnu-utils-hash-commands
|
2011-12-26 13:37:53 -05:00
|
|
|
|
2012-03-28 12:23:02 -04:00
|
|
|
function hash {
|
|
|
|
if (( $+argv[(er)-r] )) || (( $+argv[(er)-f] )); then
|
|
|
|
builtin hash "$@"
|
2012-04-02 13:06:26 -04:00
|
|
|
_gnu-utils-hash-commands
|
2011-12-26 13:37:53 -05:00
|
|
|
else
|
2012-03-28 12:23:02 -04:00
|
|
|
builtin hash "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function rehash {
|
|
|
|
hash -r "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
# A sensible default for ls.
|
|
|
|
alias ls='ls --group-directories-first'
|
|
|
|
|
|
|
|
if zstyle -t ':omz:alias:ls' color; then
|
|
|
|
if [[ -f "$HOME/.dir_colors" ]]; then
|
2012-04-02 12:00:34 -04:00
|
|
|
eval "$(dircolors "$HOME/.dir_colors")"
|
2012-04-02 11:25:22 -04:00
|
|
|
else
|
2012-04-02 12:00:34 -04:00
|
|
|
eval "$(dircolors)"
|
2011-12-26 13:37:53 -05:00
|
|
|
fi
|
2012-03-28 12:23:02 -04:00
|
|
|
alias ls="$aliases[ls] --color=auto"
|
|
|
|
else
|
|
|
|
alias ls="$aliases[ls] -F"
|
2011-02-03 17:25:45 -05:00
|
|
|
fi
|
2011-07-17 20:42:16 -04:00
|
|
|
|