-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixpath.pl.in
executable file
·72 lines (64 loc) · 2.34 KB
/
fixpath.pl.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/perl -w
# -*- mode: Perl; tab-width: 4; -*-
# Author: Alexander Hansen
# Initial release: 25 Jan, 2013.
# This script is available in the public domain.
# A quick script to tweak the PATH and MANPATH environment
# variables. The initial motivation was to make sure that
# these are the same in X11 and non-X11 terminal sessions
# on OS X 10.8.
# We read in the PATH and MANPATH environment variables and
# 1) Strip out duplicate entries.
# 2) Delete entries matching pattern given in instances
# (Zero or more) of the --delete flag.
# 3) Put the entries in the following order:
# A. Package manager, e.g. Fink.
# B. System and user-defined
# 4) Print the results to standard output in the standard
# PATH format.
use strict;
use List::MoreUtils qw { uniq };
use Getopt::Long;
my @delete_vals;
my ($manpath,$help);
my $result=GetOptions (
"manpath" => \$manpath,
"delete=s" => \@delete_vals,
"help" => \$help,
);
if ($help or !$result) {
print "Usage:\n\n";
print "fixpath.pl [--help] [--manpath] [--delete=PATTERN1] [--delete=PATTERN2] ...\n\n";
print "Reorders the PATH or MANPATH to make sure that Fink's are in the front:\n\n";
print "<Fink paths>:<system and user paths>\n\n";
print "We also remove duplicate entries, and other entries can be removed via\n";
print "the --delete flag\n\n";
print "Options:\n\n";
print "--help\t\tDisplay this text\n";
print "--manpath\toperate on MANPATH rather than PATH\n";
print "--delete\t(Optional) Zero or more patterns to exclude.\n\n";
print "Example:\n\n";
print '$ printenv PATH',"\n";
print "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:@PREFIX@/bin:@PREFIX@/sbin:@PREFIX@/lib/perl5/ExtUtils:/Users/hansen/bin:/Users/hansen/bin:/opt/X11/bin\n\n";
print '$ fixpath.pl'," --delete=local\n";
print "@PREFIX@/bin:@PREFIX@/sbin:@PREFIX@/lib/perl5/ExtUtils:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/hansen/bin\n";
exit 1;
}
my (@mgrpath, @generalpath);
my @path_entries;
if ($manpath) {
@path_entries = uniq (split /:/, $ENV{"MANPATH"});
} else {
@path_entries = uniq (split /:/, $ENV{"PATH"});
}
ENTRY: foreach my $entry (@path_entries) {
foreach (@delete_vals) {
next ENTRY if $entry =~ /$_/;
}
if ($entry =~ m|^@PREFIX@|) {
push @mgrpath, ($entry);
} else {
push @generalpath, ($entry);
}
}
print join(':', @mgrpath, @generalpath),"\n";