-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit
More file actions
50 lines (41 loc) · 1.12 KB
/
init
File metadata and controls
50 lines (41 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
export PATH
# Helper function for adding to PATH
# function _add_path() {
# if [[ -d "$1" ]] && [[ ":$PATH:" != *":$1:"* ]]; then
# PATH="$1${PATH:+":$PATH"}"
# fi
# }
function _add_path () {
# Don't add non-existant directories to path
if [[ ! -d "$1" ]]; then
return
fi
# Break path into an array, ensuing the passed value is at the front
declare -a path_arr
local IFS=':'
path_arr+=("$1")
for p in $PATH; do
if [[ "$p" != "$1" ]]; then
path_arr+=("$p")
fi
done
PATH="${path_arr[*]}"
}
# Clean all duplicates from path
function _clean_path() {
local clean_path
clean_path="$(echo "$PATH" | tr : $'\n' | awk '!x[$0]++' | tr $'\n' : | sed -E 's/^:*([^:].+[^:]):*$/\1/')"
PATH="$clean_path"
}
PROFILE_ROOT="$HOME/.profile.d"
PROFILE_STAGING="$PROFILE_ROOT/staging"
PROFILE_SCRIPTS="$PROFILE_ROOT/scripts"
PROFILE_TOOL_DIR="$PROFILE_STAGING/tools"
_add_path "$HOME/bin"
for sourced_file in "$PROFILE_STAGING/source/"*; do
# shellcheck disable=SC1090
PROFILE_SCRIPTS="$PROFILE_SCRIPTS" source "${sourced_file}"
done
_clean_path
export PROFILE_INIT_STATUS=1