Skip to content

Instantly share code, notes, and snippets.

@blizzrdof77
Created November 29, 2017 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blizzrdof77/1c776c6d922aeb553d35b97fd1bf91e2 to your computer and use it in GitHub Desktop.
Save blizzrdof77/1c776c6d922aeb553d35b97fd1bf91e2 to your computer and use it in GitHub Desktop.
Shell (bash/zsh) script to return all paths of an executable command (symlinks, function definition, etc)
## -----------------------------------------
# Return any and all paths and/or symlinks of a command
#
# @1 = command name
##
function which-all () {
if [[ -z "$1" ]]; then
echo "Script name or file path?"
read SCRPTNAME
else
SCRPTNAME=$1
fi
if [[ $($(whereis type) -t $SCRPTNAME) = "file" ]]; then
if [[ "$1" != "-f" && "$1" != "--file" ]] || [[ $($(whereis type) $SCRPTNAME &>/dev/null && echo "true" || echo "false") = "true" ]]; then
SCRPTPATH=$(which $SCRPTNAME)
else
SCRPTPATH=$SCRPTNAME
fi
if [[ $($(whereis type) -t namei-simple) = "file" ]]; then
namei-simple $SCRPTPATH
else
curl -s https://gist.githubusercontent.com/blizzrdof77/4ee14d5f2669245774f60ea2cefc65c5/raw/856be782853de0fa9bdcbbacad4eada6a260783d/namei-simple | bash /dev/stdin $SCRPTPATH
fi
else
local OUTP=$(type -a $SCRPTNAME)
if [[ -n "$ZSH_VERSION" ]]; then
which $SCRPTNAME
local OUTP="$(color underline green) $(type -a $SCRPTNAME) $(color)"
fi
echo "$OUTP"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment