-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbindir.module
28 lines (25 loc) · 945 Bytes
/
bindir.module
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
# Meant to be sourced by 'Bash Magic Enviro'
# Adds project's bin dir to path
# Checks for project's bin directory to be in path
bindir_load() {
if ! [[ -d ${BME_PROJECT_DIR}/bin ]]; then
bme_log "${C_BOLD}'${BME_PROJECT_DIR}/bin/'${C_NC} directory requested, but not found." warning 1
mkdir ${BME_PROJECT_DIR}/bin
bme_log "${C_BOLD}'${BME_PROJECT_DIR}/bin'${C_NC} created." info 1
fi
# Adds ${BME_PROJECT_DIR}/bin if not already there
if ! [[ "$PATH" =~ (^|:)"${BME_PROJECT_DIR}/bin"(:|$) ]]; then
PATH="${BME_PROJECT_DIR}/bin":$PATH
bme_log "${C_BOLD}'${BME_PROJECT_DIR}/bin'${C_NC} added to local path." info 1
fi
}
bindir_unload() {
# Passes current $PATH to an array
local OLD_IFS=$IFS && IFS=:
local tmp_path=($PATH) && IFS=$OLD_IFS
# array operation to delete project's bin entry from path
tmp_path=(${tmp_path[@]%%*${BME_PROJECT_DIR}/bin*})
IFS=:
# sets the new path
PATH=`echo "${tmp_path[*]}"` && IFS=$OLD_IFS
}