Revision 2d5a51d94568d00a412c47f64e0180fabe654cb0 authored by Jeff Bezanson on 23 February 2017, 03:35:26 UTC, committed by Jeff Bezanson on 23 February 2017, 04:23:21 UTC
1 parent 2a19c36
relative_path.sh
#!/bin/sh
# This file is a part of Julia. License is MIT: http://julialang.org/license
# both $1 and $2 are absolute paths beginning with /
# returns relative path to $2/$target from $1/$source
relpath () {
[ $# -ge 1 ] && [ $# -le 2 ] || return 1
current="${2:+"$1"}"
target="${2:-"$1"}"
[ "$target" != . ] || target=/
target="/${target##/}"
[ "$current" != . ] || current=/
current="${current:="/"}"
current="/${current##/}"
appendix="${target##/}"
relative=''
while appendix="${target#"$current"/}"
[ "$current" != '/' ] && [ "$appendix" = "$target" ]; do
if [ "$current" = "$appendix" ]; then
relative="${relative:-.}"
echo "${relative#/}"
return 0
fi
current="${current%/*}"
relative="$relative${relative:+/}.."
done
relative="$relative${relative:+${appendix:+/}}${appendix#/}"
echo "$relative"
}
relpath "$@"
Computing file changes ...