zsh-users
 help / color / mirror / code / Atom feed
From: Hank Hughes <thigpen@ccs.neu.edu>
To: Bernd Eggink <eggink@rrz.uni-hamburg.de>
Cc: Helmut Jarausch <jarausch@IGPM.Rwth-Aachen.DE>,
	zsh-users@math.gatech.edu
Subject: Re: PATH editing in a script
Date: Sun, 01 Mar 1998 20:06:25 -0500	[thread overview]
Message-ID: <199803020106.UAA15038@betelgeuse.ccs.neu.edu> (raw)
In-Reply-To: Your message of "Tue, 24 Feb 1998 15:28:31 +0100." <34F2D90E.1D128EEE@rrz.uni-hamburg.de>


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?

----------------------------------------------------------------------
#
# PATH adjustors
#
# Concepts originally from (Well, at least the first time *I* saw them)
#    Remy Evard <evard@mcs.anl.gov>
#
# Re-Inspired by parameter expansions given by 
#    Bernd Eggink <eggink@rrz.uni-hamburg.de>
#

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."

    if [ $1 ] 
    then 
	if ( [ $1 = "-i" ] || [ $1 = "-n" ] ) 
	then                         # Sort numerically by index
	    echo "Index   Directory"
	    echo "-----   ------------------------------------------------------------------------"
	    echo $PATH | awk -F: '{ for (i = 1; i <= NF; i++) printf("  %3d    %s\n", ++num, $i)}' | sort
	elif ( [ $1 = "-d" ] || [ $1 = "-a" ] )
        then                         # Sort alphabetically by directory
	    echo "Index   Directory"
	    echo "-----   ------------------------------------------------------------------------"
	    echo $PATH | awk -F: '{ for (i = 1; i <= NF; i++) printf("  %3d    %s\n", ++num, $i)}' | sort +1
	else
	    echo $usage              # Maybe default by index instead?
	fi
    else
        echo $usage
    fi
}

addpath()   { path=($path:$1) }      # Append to path
prepath()   { path=($1:$path) }      # Prepend to path
rmpath()                             # Remove from path
{                                       # Depending on tab complete ...
    dir=`echo $1 | sed 's/\/$//'`       #   Remove finicky trailing slash 
    path=(${(R)path:#$dir})             # Param expansion ...
				        #   ${name:#patt} replace with null
}
replpath()                           # Replace path with path
{ 
    dir1=`echo $1 | sed 's/\/$//'`      # The trailing slashes ..
    dir2=`echo $2 | sed 's/\/$//'`
    path[$path[(ri)$dir1]]=$dir2        # Replace matched index with new directory
} 

#nognu()   { rmpath /arch/gnu/bin }     # Zzzot gnu!



----------------------------------------------------------------------


  reply	other threads:[~1998-03-02  1:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-24 13:11 Helmut Jarausch
1998-02-24 13:31 ` Bruce Stephens
1998-02-24 14:28 ` Bernd Eggink
1998-03-02  1:06   ` Hank Hughes [this message]
1998-03-03 10:31     ` Bernd Eggink
1998-02-24 14:55 Niall Smart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199803020106.UAA15038@betelgeuse.ccs.neu.edu \
    --to=thigpen@ccs.neu.edu \
    --cc=eggink@rrz.uni-hamburg.de \
    --cc=jarausch@IGPM.Rwth-Aachen.DE \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).