about summary refs log tree commit diff stats
path: root/profile/00_functions.sh
diff options
context:
space:
mode:
Diffstat (limited to 'profile/00_functions.sh')
-rw-r--r--profile/00_functions.sh69
1 files changed, 0 insertions, 69 deletions
diff --git a/profile/00_functions.sh b/profile/00_functions.sh deleted file mode 100644 index 4bf0c78..0000000 --- a/profile/00_functions.sh +++ /dev/null
@@ -1,69 +0,0 @@
1# utility functions for all shells
2# these should be POSIX-compatible.
3
4# add a path to PATH, but only if it's not already there
5path_add_to_PATH() { # path_add_to_PATH [-a] PATH...
6 # -a appends (default is prepend)
7 APPEND=false
8 if [ "x$1" = "x-a" ]; then
9 APPEND=true
10 shift
11 fi
12
13 for p; do
14 case ":$PATH:" in
15 *:"$p":*) ;;
16 *)
17 if $APPEND; then
18 PATH="$PATH:$p"
19 else
20 PATH="$p:$PATH"
21 fi
22 ;;
23 esac
24 done
25
26 unset APPEND
27}
28
29# Generalization of `path_add_to_PATH' for any variable.
30path_add_unsafe() { #path_add_unsafe [-a] [-d DELIM] VAR PATH...
31 ## Add PATH... to VAR, delimiting with DELIM (default :).
32 # By default, the VAR will be prepended to; passing -a will append the
33 # variable. -d DELIM defines the delimiter.
34 #
35 # This function has the _unsafe suffix because it uses `eval' to set
36 # variables.
37 APPEND=false
38 DELIM=:
39 while getopts ad: opt; do
40 case "$opt" in
41 a) APPEND=true ;;
42 d) DELIM="$OPTARG" ;;
43 *) return 1 ;;
44 esac
45 done
46 shift $(expr $OPTIND - 1)
47
48 var="$1"
49 shift
50
51 for path; do
52 case ":$(eval "echo \$$var"):" in
53 *:"$path":*) ;;
54 *)
55 if $APPEND; then
56 eval "$var=\$$var${var:+$DELIM}$path"
57 else
58 eval "$var=$path${var:+$DELIM}\$$var"
59 fi
60 ;;
61 esac
62 done
63 unset -v APPEND DELIM var
64}
65
66# Re-source ~/.profile
67reprofile() {
68 . $HOME/.profile
69}