annotate .shell.d/00.path_manipulation.sh @ 217:e4842709368a

emacs: move colors to their own file and migrate to whitespace from wspace
author Augie Fackler <durin42@gmail.com>
date Sat, 14 Aug 2010 20:42:58 -0500
parents 7dfb7799567f
children c85072e620a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 # Functions for manipulating $PATH. Split out so I can use them in .zshenv if I want.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 function insert_path_element() {
135
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
4 insert_element_into_var $1 PATH
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 }
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 function remove_path_element() {
149
7dfb7799567f path_manipulation: Fix accidental recursion.
Augie Fackler <durin42@gmail.com>
parents: 135
diff changeset
8 remove_element_from_var $1 PATH
135
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
9 }
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
10
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
11 function insert_element_into_var () {
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
12 eval varcontents=\$"$2"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
13 eval varname="$2"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
14 newcomp="$1"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
15 if echo "$varcontents" | grep "$newcomp:" >> /dev/null; then
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
16 true
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
17 elif [[ "$varcontents" == "" ]] ; then
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
18 export $varname="$newcomp"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
19 else
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
20 export $varname="$newcomp:$varcontents"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
21 fi
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
22 }
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
23
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
24 function remove_element_from_var() {
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
25 eval varcontents=\$"$2"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
26 eval varname="$2"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
27 newcomp="$1"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
28 if echo "$varcontents" | grep "$newcomp:" >> /dev/null; then
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
29 export $varname="`echo $varcontents | sed s%$newcomp:%%`"
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
30 elif [[ "$varcontents" == "$newcomp" ]] ; then
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
31 unset $varname
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
32 else
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
33 echo $1 not in $varname
de6d0a9a7e3f path_manipulation: more flexible so it can be used on non-PATH items
Augie Fackler <durin42@gmail.com>
parents: 39
diff changeset
34 fi
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 }