From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26529 invoked from network); 19 Apr 2002 17:52:23 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 19 Apr 2002 17:52:23 -0000 Received: (qmail 15248 invoked by alias); 19 Apr 2002 17:52:04 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 4844 Received: (qmail 15233 invoked from network); 19 Apr 2002 17:52:02 -0000 From: "Bart Schaefer" Message-Id: <1020419175150.ZM15246@candle.brasslantern.com> Date: Fri, 19 Apr 2002 17:51:50 +0000 In-Reply-To: <545ofgfaowz.fsf@icd.teradyne.com> Comments: In reply to Vin Shelton "Convert absolute paths to relative paths" (Apr 19, 7:49am) References: <545ofgfaowz.fsf@icd.teradyne.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Vin Shelton , zsh-users@sunsite.dk Subject: Re: Convert absolute paths to relative paths MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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