Created
November 29, 2017 07:37
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ----------------------------------------- | |
# 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