Created
December 29, 2010 17:51
-
-
Save milkypostman/758800 to your computer and use it in GitHub Desktop.
Functions to include in .profile to enable OSX style aliases in the terminal.
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
function resolvealias { | |
echo $(osascript << EOS | |
tell application "Finder" | |
set theItem to (POSIX file "${1}") as alias | |
if the kind of theItem is "alias" then | |
get the posix path of ((original item of theItem) as text) | |
end if | |
end tell | |
EOS | |
) | |
} | |
function cd { | |
if [ ${#1} == 0 ]; then | |
builtin cd | |
elif [[ -d "${1}" || -L "${1}" ]]; then | |
builtin cd "${1}" | |
elif [[ -f "${1}" ]]; then | |
path=$(resolvealias "$1") | |
if [[ -z $path ]]; then | |
builtin cd "${1}" | |
else | |
builtin cd "${path}" | |
fi | |
else | |
builtin cd "${1}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment