This code lets you edit your environment variables for your current command prompt. Simply run it through pl2bat (in case you don't have WinXP), put it somewhere in your PATH (like in perl/bin), set the VISUAL environment variable to your favorite editor (if you like, notepad is the default) and type vienv at the command prompt.
Then edit, copy/paste, or whatever to your environment variables. When you save and exit, the environment of the command prompt you launched it from will be changed. It just runs the code you save, so to unset an environment variable, delete everything after the "=".
-
tye
#!/usr/bin/perl -w
use strict;
main( @ARGV );
exit( 0 );
sub main {
my( $file )= @_;
my $start= tell(DATA)
or die "Can't tell(DATA): $!";
open DATA, "+< $0" or die "Can't read self ($0): $!\n";
seek( DATA, $start, 0 )
or die "Can't fseek(DATA,$start,0): $!";
die "Expected :endofperl after __END__ of $0.\n"
unless <DATA> =~ /^\s*:endofperl\s*$/i;
open TEMP, "< $file"
or die "Can't read $file: $!\n";
chomp( my @curr= <TEMP> );
close TEMP;
my %curr= map { ( split /=/, $_, 2 )[0,1] } @curr;
system( ( $ENV{VISUAL} || "notepad" ), qq("$file") );
open TEMP, "< $file"
or die "Can't reread $file: $!\n";
chomp( my @user= <TEMP> );
close TEMP;
my %user= map { ( split /=/, $_, 2 )[0,1] } @user;
for my $key ( keys %user ) {
if( ! exists $curr{$key} ) {
next;
} elsif( $curr{$key} eq $user{$key} ) {
delete $user{$key};
}
delete $curr{$key};
}
seek( DATA, 0, 1 )
or die "Can't fseek(DATA,0,1): $!";
for my $key ( keys %curr ) {
print DATA "set $key=\n";
}
for my $key ( keys %user ) {
print DATA qq{set $key=$user{$key}\n};
}
truncate DATA, tell(DATA);
}
__END__
:endofperl
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.