summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-10-10 17:13:44 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-10-10 17:15:47 -0400
commit3f726c475192da8167b18baaa5d1ba0402ebcd0f (patch)
treed7567e95a6c9bce2423f0a58aefcf68d661f0424 /.local
parente72554e8e5bf453109b31d0797323fd7085b169c (diff)
rewrite bin/config-path
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/config-path67
1 files changed, 42 insertions, 25 deletions
diff --git a/.local/bin/config-path b/.local/bin/config-path
index 6b9019c..f4c2342 100755
--- a/.local/bin/config-path
+++ b/.local/bin/config-path
@@ -1,16 +1,22 @@
#!/bin/bash
-# All the prefixes to consider
-prefixes=(
- "$HOME"
- "$HOME/.local.`uname -m`"
- "$HOME/.local"
- "$HOME/.prefix.`uname -m`"
- "$HOME/.prefix"
- "$HOME"/.gem/ruby/*
-)
-
-######################################################################
+the_guts() {
+ # Add generic prefixes
+ add_prefix "$HOME"
+ add_prefix "$HOME/.local.$(uname -m)"
+ add_prefix "$HOME/.local"
+ add_prefix "$HOME/.prefix.$(uname -m)"
+ add_prefix "$HOME/.prefix"
+
+ # Add rubygem prefixes
+ local dir
+ for dir in "$HOME"/.gem/*; do
+ # Only add it if we have that type of ruby
+ if type "${dir##*/}" &>/dev/null; then
+ add_prefix "$dir"/*
+ fi
+ done
+}
in_array() {
local needle=$1; shift
@@ -22,30 +28,41 @@ in_array() {
return 1
}
-# Import existing values
-IFS=: paths=($PATH)
-IFS=: rubylibs=($RUBYLIB)
+add_prefix() {
+ local prefix=$1
+ local dir
-# 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[*]}"
+main() {
+ # Import existing values
+ declare -ga paths rubylibs
+ IFS=: paths=($PATH)
+ IFS=: rubylibs=($RUBYLIB)
+
+ the_guts
+
+ # Put our values into the env variables
+ IFS=: PATH="${paths[*]}"
+ IFS=: RUBYLIB="${rubylibs[*]}"
+
+ # Finally, print the values
+ # The sed bit here is the only time we call an external program
+ {
+ declare -p PATH
+ declare -p RUBYLIB
+ } | sed 's/^declare \(-\S* \)*//'
+}
-# The sed bit here is the only time we call an external program
-{
- declare -p PATH
- declare -p RUBYLIB
-} | sed 's/^declare \(-\S* \)*//'
+main