2 # ---------------------------------------------------------------------------
3 # Multi-Phasic Applications: SquirrelJME
4 # Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 # Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
6 # ---------------------------------------------------------------------------
7 # SquirrelJME is under the GNU General Public License v3+, or later.
8 # See license.mkd for licensing and copyright information.
9 # ---------------------------------------------------------------------------
10 # DESCRIPTION: Calculates the relative path from one target to another
15 # Directory of this script
16 __exedir
="$(dirname -- "$0")"
18 # No base specified, just a target
24 # Base and target specified
32 echo "Usage: $0 [target]" 1>&2
33 echo " $0 [base] [target]" 1>&2
38 __base
="$("$__exedir/absolute.sh
" "$__base")"
39 __targ
="$("$__exedir/absolute.sh
" "$__targ")"
41 # Keep going up to skip the parts of the path which are exactly the same
45 # Extract both components
46 __a
="$(echo "$__base" | cut -d '/' -f "$__i")"
47 __b
="$(echo "$__targ" | cut -d '/' -f "$__i")"
49 if [ "$__a" != "$__b" ]
57 # Go up the base directory and make dots for every path element
61 __a
="$(echo "$__base" | cut -d '/' -f "$__j")"
74 # Append elements on the second set from the base to the result
78 __b
="$(echo "$__targ" | cut -d '/' -f "$__j")"
90 # If this is not the last element, add the slash
91 __zb
="$(echo "$__targ" | cut -d '/' -f "$__j")"