Skip to content

Instantly share code, notes, and snippets.

@milkypostman
Created December 29, 2010 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milkypostman/758800 to your computer and use it in GitHub Desktop.
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.
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