diff --git a/home/-shrc b/home/-shrc index 3476472..08c7c35 100644 --- a/home/-shrc +++ b/home/-shrc @@ -8,11 +8,14 @@ has() ( # hardcoded here for convenience. refer to ~/sh/has for documentation. if [ "${1:-/}" = "${1#*[!A-Za-z_-]}" ]; then if [ "$FANCY" = 0 ] || [ "${1:-/}" = "${1#-}" ]; then alias "$1"= - unalias "$1" + unalias -- "$1" fi - if [ "$FANCY" = 1 ] || [ "${1:-/}" = "${1#*-}" ]; then + if [ "$FANCY" = 1 ]; then + eval -- "$1() (:)" + unset -f -- "$1" + elif [ "${1:-/}" = "${1#*-}" ]; then eval "$1() (:)" - unset -f "$1" + unset -f -- "$1" fi fi which -- "$1" >/dev/null 2>&1 && which -- "$1" diff --git a/sh/has b/sh/has index fc9e299..df7f8e1 100755 --- a/sh/has +++ b/sh/has @@ -10,20 +10,26 @@ has() ( ### @- print the result of `which` if the program is found, else simply ### ``` fancy=0 [ -z "$ZSH_VERSION" ] && [ -z "$BASH_VERSION" ] || fancy=1 + if [ "${1:-/}" = "${1#*[!A-Za-z_-]}" ]; then # has a simple name? + # only ash and dash support aliases beginning with hyphens. + # forcefully unalias it (regardless of if it even was an alias): if [ $fancy = 0 ] || [ "${1:-/}" = "${1#-}" ]; then - # only ash and dash support aliases beginning with hyphens. - # forcefully unalias it (regardless of if it even was an alias): alias "$1"= - unalias "$1" + unalias -- "$1" fi - if [ $fancy = 1 ] || [ "${1:-/}" = "${1#*-}" ]; then - # only bash and zsh support function names containing hyphens. - # forcefully unset it (regardless of if it even was a function): + + # only bash and zsh support function names containing hyphens. + # forcefully unset it (regardless of if it even was a function): + if [ "$FANCY" = 1 ]; then + eval -- "$1() (:)" + unset -f -- "$1" + elif [ "${1:-/}" = "${1#*-}" ]; then eval "$1() (:)" - unset -f "$1" + unset -f -- "$1" fi fi + which -- "$1" >/dev/null 2>&1 && which -- "$1" ) # this uses parentheses instead of braces so that the function is always run # in a subshell. otherwise, the user's aliases and functions may be overwritten.