From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11785 invoked from network); 3 Mar 1998 11:02:35 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 3 Mar 1998 11:02:35 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id FAA25161; Tue, 3 Mar 1998 05:34:26 -0500 (EST) Resent-Date: Tue, 3 Mar 1998 05:30:30 -0500 (EST) Sender: rz2a022@uni-hamburg.de Message-ID: <34FBDBFB.406E3A9B@rrz.uni-hamburg.de> Date: Tue, 03 Mar 1998 11:31:23 +0100 From: Bernd Eggink Organization: Regionales Rechenzentrum der Uni Hamburg X-Mailer: Mozilla 4.04 [en] (X11; I; Linux 2.0.30 i586) MIME-Version: 1.0 To: Helmut Jarausch CC: zsh-users@math.gatech.edu Subject: Re: PATH editing in a script References: <199803020106.UAA15038@betelgeuse.ccs.neu.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Resent-Message-ID: <"8mULr.0.P86.5lz-q"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1365 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Hank Hughes wrote: > > I made some `quick' hacks to edit my path whilst in hustle-mode. > The functions are listed below. Are there more correct or efficient > ways to do any of these? Hm, how about this (caution, some long lines may be broken up by the mailer): -------- -------- paths() # Print the index order and the directory { # TODO: find a builtin sequence to replace awk hell # something like `foreach dir ( $path ) { printf() }'? usage="Usage: (-i|-n) or (-d|-a) for numeric or alphabetical order." typeset p psort par typeset -R5 i=1 while getopts "inda" par do case $par in (i|n) print "Index Directory" print - "----- ------------------------------------------------------------------------" for p in $path do print "$i $p" (( ++i )) done ;; (d|a) print "Index Directory" print - "----- ------------------------------------------------------------------------" for p in ${(o)path} do i=$path[(ri)$p] print "$i $p" done ;; (*) print "$usage" esac done } addpath() { path=($path $1) } # Append to path prepath() { path=($1 $path) } # Prepend to path rmpath() # Remove from path { # Depending on tab complete ... path=(${(R)path:#${1%/}}) } replpath() # Replace path with path { path[$path[(ri)${1%/}]]=${2%/} # Replace matched index with new directory } -------- -------- You don't need 'awk'. Zsh can do it all. Note that the way you added a component to $path has been wrong. $path is an array, $PATH isn't, so either path=($path $1) or PATH=$PATH:$1, but not path=($path:$1) BTW, for practical use you'd probabely better use an index as parameter for rmpath and replpath. Regards, Bernd -- Bernd Eggink Regionales Rechenzentrum der Universitaet Hamburg eggink@rrz.uni-hamburg.de http://www.rrz.uni-hamburg.de/eggink/BEggink.html