diff options
author | Mike Crute <mike@crute.us> | 2019-01-21 05:41:25 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2019-01-21 05:41:25 +0000 |
commit | 3d558784cf631f79caeedb731a37f171955633fa (patch) | |
tree | d5aab52bf8bdc8e1e6ca1594ae82ca3e15b2749f /.bashrc | |
parent | ba12c4953e30e64e1d14b394c8d6a1d0fe397564 (diff) | |
download | dotfiles-3d558784cf631f79caeedb731a37f171955633fa.tar.bz2 dotfiles-3d558784cf631f79caeedb731a37f171955633fa.tar.xz dotfiles-3d558784cf631f79caeedb731a37f171955633fa.zip |
Cleanup path manipulation
Diffstat (limited to '.bashrc')
-rw-r--r-- | .bashrc | 44 |
1 files changed, 33 insertions, 11 deletions
@@ -30,7 +30,7 @@ function load_all_from | |||
30 | # | 30 | # |
31 | # usage: add_to_path_var <var_name> <path_value> [suffix] | 31 | # usage: add_to_path_var <var_name> <path_value> [suffix] |
32 | # | 32 | # |
33 | # This function will (by default) prefix a path-like variable with another | 33 | # This function will (by default) suffix a path-like variable with another |
34 | # path, provided the path does not already exist in the variable. If it does no | 34 | # path, provided the path does not already exist in the variable. If it does no |
35 | # action is taken. Passing a third argument of 1 will result in the path being | 35 | # action is taken. Passing a third argument of 1 will result in the path being |
36 | # appended to the variable. | 36 | # appended to the variable. |
@@ -39,19 +39,19 @@ function add_to_path_var() | |||
39 | { | 39 | { |
40 | local var_name="$1" | 40 | local var_name="$1" |
41 | local add_value="$2" | 41 | local add_value="$2" |
42 | local suffix=${3:-0} | 42 | local prefix=${3:-0} |
43 | 43 | ||
44 | case :${!var_name}: in | 44 | case :${!var_name}: in |
45 | *:$add_value:*) | 45 | *:${add_value}:*) |
46 | ;; | 46 | ;; |
47 | *) | 47 | *) |
48 | if [ -z "${!var_name}" ]; then | 48 | if [ -z "${!var_name}" ]; then |
49 | eval "$var_name=$add_value" | 49 | eval "$var_name=$add_value" |
50 | else | 50 | else |
51 | if [ "$suffix" == "1" ]; then | 51 | if [ $prefix -eq 1 ]; then |
52 | eval "$var_name=${!var_name}:$add_value" | ||
53 | else | ||
54 | eval "$var_name=$add_value:${!var_name}" | 52 | eval "$var_name=$add_value:${!var_name}" |
53 | else | ||
54 | eval "$var_name=${!var_name}:$add_value" | ||
55 | fi | 55 | fi |
56 | fi | 56 | fi |
57 | ;; | 57 | ;; |
@@ -214,9 +214,25 @@ alias testify="watchr ~/.watchr.rb" | |||
214 | # | 214 | # |
215 | # SETUP SYSTEM PATHS | 215 | # SETUP SYSTEM PATHS |
216 | # | 216 | # |
217 | PATH="/usr/local/bin:/usr/local/sbin:$HOME/bin:$PATH" | 217 | # Start clean with stuff we want to override the system path |
218 | _OPATH="$PATH" | ||
219 | PATH="/usr/local/bin:/usr/local/sbin" | ||
220 | |||
221 | # Push on all the system default stuff | ||
222 | _IFS="$IFS"; IFS=: | ||
223 | for pc in $_OPATH; do | ||
224 | case "$pc" in | ||
225 | # Why do distros seem to like to put this crap on the path? | ||
226 | /usr/games|/usr/local/games) ;; | ||
227 | # Skip past these, we'll add them later if relevant and want to prefix | ||
228 | # them to the path not have them de-duplicated in-place | ||
229 | "$HOME"/*) ;; | ||
230 | *) add_to_path_var PATH "$pc" ;; | ||
231 | esac | ||
232 | done | ||
233 | IFS="$_IFS"; unset _IFS | ||
218 | 234 | ||
219 | # Local path setup | 235 | # Locally compiled stuff |
220 | LOCAL_PATH="$HOME/.local" | 236 | LOCAL_PATH="$HOME/.local" |
221 | if [[ -e "$LOCAL_PATH" ]]; then | 237 | if [[ -e "$LOCAL_PATH" ]]; then |
222 | _include="-I${LOCAL_PATH}/include" | 238 | _include="-I${LOCAL_PATH}/include" |
@@ -231,8 +247,13 @@ if [[ -e "$LOCAL_PATH" ]]; then | |||
231 | fi | 247 | fi |
232 | unset _ldflags | 248 | unset _ldflags |
233 | 249 | ||
234 | add_to_path_var PATH "${LOCAL_PATH}/bin" | 250 | add_to_path_var PATH "${LOCAL_PATH}/bin" 1 |
235 | add_to_path_var PATH "${LOCAL_PATH}/sbin" | 251 | add_to_path_var PATH "${LOCAL_PATH}/sbin" 1 |
252 | fi | ||
253 | |||
254 | # This should take precedence over the $HOME/.local stuff | ||
255 | if [[ -e "$HOME/bin" ]]; then | ||
256 | add_to_path_var PATH "$HOME/bin" 1 | ||
236 | fi | 257 | fi |
237 | 258 | ||
238 | if [[ -d /Applications/Postgres.app ]]; then | 259 | if [[ -d /Applications/Postgres.app ]]; then |
@@ -244,10 +265,11 @@ if [[ -d /Applications/Postgres.app ]]; then | |||
244 | fi | 265 | fi |
245 | 266 | ||
246 | if [[ -d /usr/local/go ]]; then | 267 | if [[ -d /usr/local/go ]]; then |
247 | add_to_path_var PATH "/usr/local/go/bin" 1 | 268 | add_to_path_var PATH "/usr/local/go/bin" |
248 | fi | 269 | fi |
249 | 270 | ||
250 | export PATH CFLAGS LDFLAGS | 271 | export PATH CFLAGS LDFLAGS |
272 | unset _OPATH | ||
251 | 273 | ||
252 | # | 274 | # |
253 | # COMMAND ALIASES | 275 | # COMMAND ALIASES |