diff options
author | Luke Shumaker <shumakl@purdue.edu> | 2015-02-09 22:17:02 -0500 |
---|---|---|
committer | Luke Shumaker <shumakl@purdue.edu> | 2015-02-09 22:17:02 -0500 |
commit | fee80e06d8cb661ee70cd4d676b5455c163b650e (patch) | |
tree | cbcdeab335afe219037665667cbc7e99c70f095e | |
parent | a634d94ab251b9d25d09e83b8c92ccbe85c74667 (diff) |
path.sh, config-path: don't rely on external programs (sed)
-rw-r--r-- | .config/login.d/00_path.sh | 4 | ||||
-rwxr-xr-x | .local/bin/config-path | 16 |
2 files changed, 8 insertions, 12 deletions
diff --git a/.config/login.d/00_path.sh b/.config/login.d/00_path.sh index a45f8fd..f4ca3a6 100644 --- a/.config/login.d/00_path.sh +++ b/.config/login.d/00_path.sh @@ -1,9 +1,7 @@ -#!/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 /')" +eval "$(IFS=$'\n'; lines=($("$config_path")); printf -- 'export %s\n' "${lines[@]}")" diff --git a/.local/bin/config-path b/.local/bin/config-path index 7cd1fcd..1d4d4d1 100755 --- a/.local/bin/config-path +++ b/.local/bin/config-path @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # All the prefixes to consider prefixes=( @@ -61,14 +61,12 @@ main() { done # Finally, print the values - # The `sed` bit here is the only time we call an external program - { - var_done PATH - var_done MANPATH - var_done LD_LIBRARY_PATH - var_done RUBYLIB - var_done PERL5LIB - } | sed 's/^declare \(-\S* \)*//' + lines=() + for var in PATH MANPATH LD_LIBRARY_PATH RUBYLIB PERL5LIB; do + lines+=("$(var_done "$var")") + done + shopt -s extglob + printf -- '%s\n' "${lines[@]##declare *(-+([[:graph:]]) )}" } main "$@" |