Skip to content

Instantly share code, notes, and snippets.

@DGrady
Last active July 19, 2016 16:04
Show Gist options
  • Select an option

  • Save DGrady/8a53dd33bacd7eff2e4c42d43b489469 to your computer and use it in GitHub Desktop.

Select an option

Save DGrady/8a53dd33bacd7eff2e4c42d43b489469 to your computer and use it in GitHub Desktop.
Shell (zsh) function for getting the absolute path of its argument
function abspath() {
# generate absolute path from relative path
# $1 : relative filename
# return : absolute path
# From http://stackoverflow.com/a/23002317/514210
if [[ -d "$1" ]]; then
# dir
(cd "$1"; pwd)
elif [[ -f "$1" ]]; then
# file
if [[ $1 == */* ]]; then
echo "$(cd "${1%/*}"; pwd)/${1##*/}"
else
echo "$(pwd)/$1"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment