blob: 99f0910e69f9db30d87dfc9725af465db2894d56 (
plain)
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
|
#!/bin/bash
# All the prefixes to consider
prefixes=(
"$HOME"
"$HOME/.local.`uname -m`"
"$HOME/.local"
"$HOME/.prefix.`uname -m`"
"$HOME/.prefix"
"$HOME"/.gem/ruby/*
)
######################################################################
in_array() {
local needle=$1; shift
local haystack=("$@")
local straw
for straw in "${haystack[@]}"; do
[[ "$needle" == "$straw" ]] && return 0
done
return 1
}
# Import existing values
IFS=: paths=($PATH)
IFS=: manpaths=($MANPATH)
IFS=: rubylibs=($RUBYLIB)
IFS=: perl5libs=($PERL5LIB)
# Scan through prefixes
for prefix in "${prefixes[@]}"; do
# PATH
for dir in "$prefix/bin" "$prefix/sbin"; do
if [[ -d "$dir" ]] && ! in_array "$dir" "${paths[@]}"; then
paths=("$dir" "${paths[@]}")
fi
done
# MANPATH
dir="$prefix/share/man"
if [[ -d "$dir" ]] && ! in_array "$dir" "${manpaths[@]}"; then
manpaths=("$dir" "${manpaths[@]}")
fi
# RUBYLIB
dir="$prefix/lib"
if [[ -d "$dir" ]] && ! in_array "$dir" "${rubylibs[@]}"; then
rubylibs=("$dir" "${rubylibs[@]}")
fi
# PERL5LIB
for dir in "$prefix"/lib*/perl5; do
if [[ -d "$dir" ]] && in_array "$dir" "${manpaths[@]}"; then
perl5libs=("$dir" "${perl5libs[@]}")
fi
done
done
# Finally, print our values
IFS=: PATH="${paths[*]}"
IFS=: MANPATH="${manpaths[*]}"
IFS=: RUBYLIB="${rubylibs[*]}"
IFS=: PERL5LIB="${perl5libs[*]}"
# The sed bit here is the only time we call an external program
{
declare -p PATH
declare -p MANPATH
declare -p RUBYLIB
declare -p PERL5LIB
} | sed 's/^declare \(-\S* \)*//'
|