Created
October 20, 2013 19:14
-
-
Save obfusk/7073906 to your computer and use it in GitHub Desktop.
relative path
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
# 1 | |
# usage: relpath <to> <from> | |
relpath () { python -c \ | |
'import os.path, sys; print os.path.relpath(*sys.argv[1:])' "$@"; } | |
# 2 | |
rel_bin="${bin#"$PREFIX"}" | |
rel_dir="${dir#"$PREFIX"}" | |
if [ "$bin" != "$rel_bin" -a "$dir" != "$rel_dir" ]; then | |
d="$rel_bin" up='' | |
while [ "$d" != / -a "$d" != . ]; do | |
up+=../; d="$( dirname "$d" )" | |
done | |
link_path () { echo "${up%/}$rel_dir/$1"; } | |
else | |
link_path () { $READLINK_F "$dir/$1"; } | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment