-
Notifications
You must be signed in to change notification settings - Fork 1
/
shrc_helpers
executable file
·102 lines (88 loc) · 3.03 KB
/
shrc_helpers
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Source helper function definitions
__rc_helpers_main() {
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
local SH_INTERACTIVE
case $- in
*i*)
# interactive shell
SH_INTERACTIVE=1
;;
esac
__add_to_path() {
local SHOW_HEADER=1
__add_to_path_no_header $*
}
__add_to_path_no_header() {
local PATH_DIRS PATH_DIR PATH_DIRS_LIST
PATH_DIRS=( $* )
for PATH_DIR in "${PATH_DIRS[@]}"; do
if [[ -d $PATH_DIR ]]; then
if [[ ":$PATH:" != *":$PATH_DIR:"* ]]; then
if [[ -n $SHOW_HEADER ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Adding to the '$COLOR_CYAN_BOLD'path'$COLOR_NONE':'
unset SHOW_HEADER
fi
[[ $SH_INTERACTIVE ]] && echo -e ' '$COLOR_YELLOW_BOLD$PATH_DIR$COLOR_NONE
if [[ -n $PATH_DIRS_LIST ]]; then
PATH_DIRS_LIST=$PATH_DIRS_LIST:$PATH_DIR
else
PATH_DIRS_LIST=$PATH_DIR
fi
fi
fi
done
if [[ -n $PATH_DIRS_LIST ]]; then
if [[ -n $PATH ]]; then
export PATH=$PATH_DIRS_LIST:$PATH
else
export PATH=$PATH_DIRS_LIST
fi
fi
}
__add_to_cd_path() {
local SHOW_HEADER=1
__add_to_cd_path_no_header $*
}
__add_to_cd_path_no_header() {
local CDPATH_DIRS CDPATH_DIR CDPATH_DIRS_LIST
CDPATH_DIRS=( $* )
for CDPATH_DIR in "${CDPATH_DIRS[@]}"; do
if [[ -d $CDPATH_DIR ]]; then
if [[ ":$CDPATH:" != *":$CDPATH_DIR:"* ]]; then
if [[ -n $SHOW_HEADER ]]; then
[[ $SH_INTERACTIVE ]] && echo
[[ $SH_INTERACTIVE ]] && echo -e 'Adding to the '$COLOR_CYAN_BOLD'cd path'$COLOR_NONE':'
unset SHOW_HEADER
fi
[[ $SH_INTERACTIVE ]] && echo -e ' '$COLOR_YELLOW_BOLD$CDPATH_DIR$COLOR_NONE
if [[ -n $CDPATH_DIRS_LIST ]]; then
CDPATH_DIRS_LIST=$CDPATH_DIRS_LIST:$CDPATH_DIR
else
CDPATH_DIRS_LIST=$CDPATH_DIR
fi
fi
fi
done
if [[ -n $CDPATH_DIRS_LIST ]]; then
if [[ -n $CDPATH ]]; then
export CDPATH=$CDPATH:$CDPATH_DIRS_LIST
else
export CDPATH=$CDPATH_DIRS_LIST
fi
fi
}
__include_files() {
local SH_FILES SH_FILE
SH_FILES=( $* )
for SH_FILE in "${SH_FILES[@]}"; do
if [[ -f "$SH_FILE" ]]; then
[[ $SH_INTERACTIVE ]] && echo -e 'Loading '$COLOR_GREEN_BOLD$SH_FILE$COLOR_NONE
. "$SH_FILE"
fi
done
}
}
__rc_helpers_main "$@"
unset -f __rc_helpers_main