Skip to content

Instantly share code, notes, and snippets.

@obfusk
Created October 20, 2013 19:14
Show Gist options
  • Save obfusk/7073906 to your computer and use it in GitHub Desktop.
Save obfusk/7073906 to your computer and use it in GitHub Desktop.
relative path
# 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