Last active
July 19, 2016 16:04
-
-
Save DGrady/8a53dd33bacd7eff2e4c42d43b489469 to your computer and use it in GitHub Desktop.
Shell (zsh) function for getting the absolute path of its argument
This file contains hidden or 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 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