From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1240 invoked from network); 20 Apr 2002 00:48:28 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 20 Apr 2002 00:48:28 -0000 Received: (qmail 20230 invoked by alias); 20 Apr 2002 00:48:12 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4848 Received: (qmail 20217 invoked from network); 20 Apr 2002 00:48:10 -0000 To: "Bart Schaefer" Cc: zsh-users@sunsite.dk Subject: Re: Convert absolute paths to relative paths References: <545ofgfaowz.fsf@icd.teradyne.com> <1020419175150.ZM15246@candle.brasslantern.com> From: Vin Shelton Organization: EtherSoft, Inc Date: Fri, 19 Apr 2002 20:47:13 -0400 In-Reply-To: <1020419175150.ZM15246@candle.brasslantern.com> ("Bart Schaefer"'s message of "Fri, 19 Apr 2002 17:51:50 +0000") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Thanks, Bart! - vin "Bart Schaefer" 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