Created
January 19, 2019 20:58
-
-
Save dougpagani/adb1f8122cd7460c41ad05ae0f85c552 to your computer and use it in GitHub Desktop.
Ask what "tf" is up with this cmd, which is often a symlinked-file (think brew Cellars). Also good for getting to a python-cli wrapper's lib dir.
This file contains 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
typify-file () | |
{ | |
opwd="$PWD"; | |
type -a "$1"; | |
cmdpath=$(type -P "$1"); | |
if ( test -e "$cmdpath" ); then | |
count=0; | |
while ( test -L "$cmdpath" ); do | |
(( count++ )); | |
linkrelative=$(readlink -n "$cmdpath"); | |
pink="$PURPLE"; | |
ec="\033[0m"; | |
printf "\t${count}. ${pink}${cmdpath}${ec} ---> ${linkrelative}\n"; | |
cmdpathdir="$(dirname "$cmdpath")"; | |
cd "$cmdpathdir"; | |
cmdpath="$(realpath -s "$linkrelative")"; | |
done; | |
printf "\nFILE: "; | |
\file -h --no-dereference "$cmdpath" | sed 's/:/\n>> /'; | |
printf "\nMIME: "; | |
\file -h --no-dereference --mime-type -b "$cmdpath"; | |
echo; | |
echo "cd - ... to go to the final dir"; | |
fi; | |
cd "$owd" | |
} | |
alias tf=typify-file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment