commit a4643be1733d03a1a6b6a3e3c7a87995eee01b56 parent 13023c05f11a342147c173cb5a0f2b4b32216462 Author: Alex Balgavy <a.balgavy@gmail.com> Date: Sat, 14 Apr 2018 20:33:37 +0200 Added realpath function Prints the path to a specific file/directory. If used with flag -w, prints with the name of the file/directory. Diffstat:
M | .commonprofile | | | 25 | +++++++++++++++++++++++++ |
1 file changed, 25 insertions(+), 0 deletions(-)
diff --git a/.commonprofile b/.commonprofile @@ -112,6 +112,31 @@ gdf() { echo `osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'` } +realpath() { + if [ $# -eq 1 ]; then + if [ -e $1 ]; then + if [ -L $1 ]; then + echo `readlink $1 | rev | cut -d/ -f2- | rev` + else + echo `pwd`/`readlink $1 | rev | cut -d/ -f2- | rev` + fi + else + echo "File does not exist." + fi + elif [ "$1" = "-w" ]; then + if [ -e $2 ]; then + if [ -L $2 ]; then + echo `readlink $2` + else + echo `pwd`/`readlink $2` + fi + else + echo "File does not exist." + fi + else + echo 'idk what you want dude' + fi +} ######################