delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/07/29/00:18:36

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <3D44C20F.7030005@attbi.com>
Date: Sun, 28 Jul 2002 23:18:23 -0500
From: "Cyber.Zombie" <Cyber DOT Zombie AT attbi DOT com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1b) Gecko/20020721
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: "Gary R. Van Sickle" <g DOT r DOT vansickle AT worldnet DOT att DOT net>
CC: Cygwin mailing list <cygwin AT cygwin DOT com>
Subject: Re: Useful Cygwinism #2: PATH Despacifier/Deduplicateifier
References: <NCBBIHCHBLCMLBLOBONKCEOEDCAA DOT g DOT r DOT vansickle AT worldnet DOT att DOT net>

A suggested improvement:  Sometimes multiple paths are mount points to 
the same directory and won't get noticed until the path has been 
corrected.  The following rework will further cleanup $PATH:

#!/usr/bin/perl -w
#
use strict;
my @pathcomps;
my @pathcomps_out;
my %comps_seen_already;
@pathcomps = split(/:/, shift);
for(@pathcomps) {
        my $path='"'.$_.'"';
        $path=qx(cygpath -u \$(cygpath -ws $path));
        $path=~tr/\n//d;
        if(!exists($comps_seen_already{$path})) {
                push(@pathcomps_out, $path);
                $comps_seen_already{$path}=1;
        }
}
print join(":", @pathcomps_out);

Gary R. Van Sickle wrote:

>I've been noticing a lot of traffic lately on people having problems with paths
>which contain spaces, admonitions to "keep your PATH as short as possible for
>performance reasons", etc.  So in the spirit of floating everyone's boat, here's
>installment #2 of "Useful Cygwinisms".
>
>PROBLEM:
>Your Windows PATH contains paths with spaces in them, causing you all manner of
>grief.  It also contains the Windows paths to /bin and /usr/local/bin, to make
>running Cygwin apps from the 9x/NT command line easier, but these end up getting
>needlessly duplicated when you run a bash session, due to the actions of
>/etc/profile.
>
>SOLUTION:
>A little Perl script I like to call "despaceify":
>
>=========================================================
>#!/usr/bin/perl -w
>use strict;
>my @pathcomps;
>my @pathcomps_out;
>my %comps_seen_already;
>@pathcomps = split(/:/, shift);
>for(@pathcomps)
>{
>        if(!exists($comps_seen_already{$_}))
>        {
>                my $path;
>                $path='"'.$_.'"';
>                $path=qx(cygpath -u \$(cygpath -ws $path));
>                $path=~tr/\n//d;
>                push(@pathcomps_out, $path);
>        }
>        $comps_seen_already{$_}=1;
>}
>print join(":", @pathcomps_out);
>==========================================================
>
>This script takes a ":"-separated Unixoid PATH, replaces any component paths
>containing spaces with their equivalent "8.3" spaceless replacements, and also
>removes any duplicates (only the first instance of a particular path will
>remain).  To make it work its magic, just save the script as "despaceify"
>somewhere convenient (for me, ~/bin/despaceify), of course make sure you have
>Perl installed, and then add this to your .bash_profile:
>
># Clean up PATH.
>export PATH=$(~/bin/despaceify "$PATH");
>
>And that's it.  Every time you start up a bash session, your PATH will be
>automatically scrubbed clean!
>
>COMMENTS:
>This addition adds a slightly annoying ~1-2 second delay to bash startup,
>probably from the loading of Perl.  However, my Herculean efforts to get such
>functionality without Perl (i.e. with just shell scripting and cygpath) came to
>naught.  I'm guessing an equivalent script might be possible in awk, but that's
>an exercise (==challenge) for the reader ;-).
>
>FINE PRINT:
>Offer void in CA, AK, WA, and where prohibited by law.  No bailment created.
>Not to be used as a flotation device.  Phenylketonurics: Contains phenylalanine.
>To be used only for good, never evil.  Contains less than 10% fruit juice.  May
>not be suitable for some viewers.  Light fuse and get away.
>
>--
>Gary R. Van Sickle
>Brewer.  Patriot.
>
>
>--
>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>Bug reporting:         http://cygwin.com/bugs.html
>Documentation:         http://cygwin.com/docs.html
>FAQ:                   http://cygwin.com/faq/
>
>
>  
>





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019