Skip to content

Instantly share code, notes, and snippets.

@dougpagani
Created January 19, 2019 20:58
Show Gist options
  • Save dougpagani/adb1f8122cd7460c41ad05ae0f85c552 to your computer and use it in GitHub Desktop.
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.
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