Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Convert absolute paths to relative paths
- X-seq: zsh-users 4848
- From: Vin Shelton <acs@xxxxxxxxxxxxxxxxxxxx>
- To: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Convert absolute paths to relative paths
- Date: Fri, 19 Apr 2002 20:47:13 -0400
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <1020419175150.ZM15246@xxxxxxxxxxxxxxxxxxxxxxx> ("Bart Schaefer"'s message of "Fri, 19 Apr 2002 17:51:50 +0000")
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: EtherSoft, Inc
- References: <545ofgfaowz.fsf@xxxxxxxxxxxxxxxx> <1020419175150.ZM15246@xxxxxxxxxxxxxxxxxxxxxxx>
Thanks, Bart!
- vin
"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> writes:
> On Apr 19, 7:49am, Vin Shelton wrote:
> }
> } Can anyone show me some nifty zsh hackery to convert a string
> } representing an absolute path into a relative path? For example, if
> } my current $PWD is "/opt/build" and the path I want to convert is
> } "/opt/src/perl-5.6.1", I would like the result to be
> } "../src/perl-5.6.1".
>
> function relative {
> emulate -L zsh
> local up=.. down
> # ! -d $up/$down accounts for symlinks in $PWD
> while [[ ${PWD#$1} == $PWD || ! -d $up/$down ]]
> do
> up=../$up
> if [[ -n $1:t ]]
> then
> down=$1:t${down:+/$down}
> 1=$1:h
> fi
> done
> print $up/$down
> }
>
> --
> Bart Schaefer Brass Lantern Enterprises
> http://www.well.com/user/barts http://www.brasslantern.com
>
> Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author