summaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-08-14 15:51:54 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-08-14 15:51:54 -0400
commit3f570eac4afc3299fa2a55b39c57fae7f457bc84 (patch)
tree21250586016b1f4b93f2d23a3377a1a8e3313f59 /.local/bin
parent4652fb938285ad72a3d21042c118361969176f80 (diff)
re-jigger to allow easier setting of the path
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/config-path51
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..a5c3b0e
--- /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/bin"
+ "$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")
+ fi
+ # RUBYLIB
+ dir="$prefix/lib"
+ if [[ -d "$dir" ]] && ! in_array "$dir" "${rubylibs[@]}"; then
+ rubylibs+=("$dir")
+ 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* \)*//'