Skip to content

Instantly share code, notes, and snippets.

@joepvd
Last active January 8, 2022 17:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepvd/fa76322514895617fac2241377c4c1ec to your computer and use it in GitHub Desktop.
Save joepvd/fa76322514895617fac2241377c4c1ec to your computer and use it in GitHub Desktop.
# Love you, GNU. But got a bit tired of this conversation pattern:
#
# % ln -h
# ln: invalid option -- 'h'
# Try 'ln --help' for more information.
#
# Don't worry. I fixed you for me.
#
# Eternally yours,
#
# github.com/joepvd
for util in base64 basename cat chmod chroot cksum comm cp csplit cut dd \
dirname env factor fmt groups head hostid hostname id install join \
ln logname md5sum mkdir mkfifo mknod mktemp mv nice nohup nproc \
paste pathchk printenv ptx readlink realpath rm rmdir runcon seq \
shuf sleep split stat stdbuf stty sum sync tac tail tee timeout tr \
tsort tty uname unexpand uniq unlink uptime users wc who whoami yes \
$(: and non coreutils :) \
date
do function $util {
if [[ "$1" == -h ]]
then command "$0" --help
else command "$0" "$@"
fi
}
done; unset util
@ssokolow
Copy link

ssokolow commented Nov 7, 2019

Just a little tip I stumbled across: The eval isn't necessary. Zsh allows you to define a function with a name taken from a variable and $0 can substitute for the uses of $util in the function body.

do  function $util {
        if [[ $1 == -h ]]
        then command "$0" --help
        else command "$0" "$@"
        fi
    }

Also, ls probably shouldn't be in that list unless you add a check for $# == 1 because ls uses -h to mean --human-readable and, if someone aliases ls=ls -h to default to human-friendly filesizes, you'll get every attempt to invoke ls being changed to ls --help instead.

@joepvd
Copy link
Author

joepvd commented Nov 20, 2019

Excellent, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment