summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.config/cron/make-config2
-rw-r--r--.config/login.sh25
-rwxr-xr-x.local/bin/config-path51
-rw-r--r--.local/lib/path.sh9
4 files changed, 63 insertions, 24 deletions
diff --git a/.config/cron/make-config b/.config/cron/make-config
index afe690d..448475b 100644
--- a/.config/cron/make-config
+++ b/.config/cron/make-config
@@ -1,2 +1,2 @@
# m h dom mon dow command
-*/5 * * * * . $HOME/.local/lib/xdg.sh && make -C $XDG_CONFIG_HOME
+*/5 * * * * . $HOME/.local/lib/path.sh && . $HOME/.local/lib/xdg.sh && make -C $XDG_CONFIG_HOME
diff --git a/.config/login.sh b/.config/login.sh
index 0a358f2..3dad752 100644
--- a/.config/login.sh
+++ b/.config/login.sh
@@ -13,28 +13,7 @@ umask 022
## Paths #############################################################
-# Unix
-prefixes=(
- "$HOME"
- "$HOME/.local.`uname -m`"
- "$HOME/.local/bin"
- "$HOME/.prefix.`uname -m`"
- "$HOME/.prefix"
- "$HOME"/.gem/ruby/*
-)
-for prefix in "${prefixes[@]}"; do
- if [[ -d "$prefix/bin" ]]; then
- export PATH="$prefix/bin:$PATH"
- fi
-done
-
-# Ruby
-for dir in "$HOME"/.prefix/lib; do
- if [[ -d "$dir" ]]; then
- export RUBYLIB="$dir"
- fi
-done
-unset prefixes dir prefix
+. "$HOME/.local/lib/path.sh"
# TMPDIR #############################################################
@@ -86,7 +65,7 @@ export _JAVA_OPTIONS
# X11
if [[ -z $XAUTHORITY ]]; then
- export XAUTHORITY=$HOME/.Xauthority
+ export XAUTHORITY="$HOME/.Xauthority"
fi
# D-Bus
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* \)*//'
diff --git a/.local/lib/path.sh b/.local/lib/path.sh
new file mode 100644
index 0000000..a45f8fd
--- /dev/null
+++ b/.local/lib/path.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+if type config-path &>/dev/null; then
+ config_path=config-path
+else
+ # Bootstrap finding config-path
+ config_path="$HOME/.local/bin/config-path"
+fi
+eval "$("$config_path" | sed 's/^/export /')"