diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-10-12 19:12:40 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2013-10-12 19:12:40 -0400 |
commit | 8ff950d098146bc929504b062bcc6ccd5a2cb6ed (patch) | |
tree | e5d73cf1997b28bbaa24a693f5d8c2abb45be313 /.local/bin/config-path | |
parent | 9d689e7d224b5c1ea3ab3018998135979f19c5a9 (diff) | |
parent | b0cdbb3da2c2b36d3c65b00db4eaf5a0d29c2cd6 (diff) |
Merge remote-tracking branch 'origin/master' into build64-par
Conflicts:
.config/bash/rc.sh
.config/login.sh
.config/ssh/config
.config/wmii/include.sh
Diffstat (limited to '.local/bin/config-path')
-rwxr-xr-x | .local/bin/config-path | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/.local/bin/config-path b/.local/bin/config-path new file mode 100755 index 0000000..6b9019c --- /dev/null +++ b/.local/bin/config-path @@ -0,0 +1,51 @@ +#!/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=: rubylibs=($RUBYLIB) + +# Scan through prefixes +for prefix in "${prefixes[@]}"; do + # PATH + dir="$prefix/bin" + if [[ -d "$dir" ]] && ! in_array "$dir" "${paths[@]}"; then + paths=("$dir" "${paths[@]}") + fi + # RUBYLIB + dir="$prefix/lib" + if [[ -d "$dir" ]] && ! in_array "$dir" "${rubylibs[@]}"; then + rubylibs=("$dir" "${rubylibs[@]}") + fi +done + +# Finally, print our values +IFS=: PATH="${paths[*]}" +IFS=: RUBYLIB="${rubylibs[*]}" + +# The sed bit here is the only time we call an external program +{ + declare -p PATH + declare -p RUBYLIB +} | sed 's/^declare \(-\S* \)*//' |