summaryrefslogtreecommitdiff
path: root/.bashrc
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2019-01-21 05:41:25 +0000
committerMike Crute <mike@crute.us>2019-01-21 05:41:25 +0000
commit3d558784cf631f79caeedb731a37f171955633fa (patch)
treed5aab52bf8bdc8e1e6ca1594ae82ca3e15b2749f /.bashrc
parentba12c4953e30e64e1d14b394c8d6a1d0fe397564 (diff)
downloaddotfiles-3d558784cf631f79caeedb731a37f171955633fa.tar.bz2
dotfiles-3d558784cf631f79caeedb731a37f171955633fa.tar.xz
dotfiles-3d558784cf631f79caeedb731a37f171955633fa.zip
Cleanup path manipulation
Diffstat (limited to '.bashrc')
-rw-r--r--.bashrc44
1 files changed, 33 insertions, 11 deletions
diff --git a/.bashrc b/.bashrc
index 869e6e4..725b7d4 100644
--- a/.bashrc
+++ b/.bashrc
@@ -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#
217PATH="/usr/local/bin:/usr/local/sbin:$HOME/bin:$PATH" 217# Start clean with stuff we want to override the system path
218_OPATH="$PATH"
219PATH="/usr/local/bin:/usr/local/sbin"
220
221# Push on all the system default stuff
222_IFS="$IFS"; IFS=:
223for 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
232done
233IFS="$_IFS"; unset _IFS
218 234
219# Local path setup 235# Locally compiled stuff
220LOCAL_PATH="$HOME/.local" 236LOCAL_PATH="$HOME/.local"
221if [[ -e "$LOCAL_PATH" ]]; then 237if [[ -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
252fi
253
254# This should take precedence over the $HOME/.local stuff
255if [[ -e "$HOME/bin" ]]; then
256 add_to_path_var PATH "$HOME/bin" 1
236fi 257fi
237 258
238if [[ -d /Applications/Postgres.app ]]; then 259if [[ -d /Applications/Postgres.app ]]; then
@@ -244,10 +265,11 @@ if [[ -d /Applications/Postgres.app ]]; then
244fi 265fi
245 266
246if [[ -d /usr/local/go ]]; then 267if [[ -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"
248fi 269fi
249 270
250export PATH CFLAGS LDFLAGS 271export PATH CFLAGS LDFLAGS
272unset _OPATH
251 273
252# 274#
253# COMMAND ALIASES 275# COMMAND ALIASES