-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot.bash_profile
162 lines (140 loc) · 7.46 KB
/
dot.bash_profile
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
# shellcheck disable=SC2155 disable=SC2012 disable=SC2153
######################################
# ConfigShell lib 1.1 (codebase 1.0.0)
bashLib="/opt/ConfigShell/lib/bashlib.sh"
[ ! -f "$bashLib" ] && 1>&2 echo "bash-library $bashLib not found" && return # no exit for bash_profile or bashrc
# shellcheck source=/opt/ConfigShell/lib/bashlib.sh
source "$bashLib"
unset bashLib
##########################
function setupPathsFromFiles() {
debug12 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '...............................................'
# 1
debug12 "PREPENDING global PATH ENTRIES ........"
[ -r "$PROFILES_CONFIG_DIR/Shell/path.prepend.txt" ] && \
while IFS= read -r line ; do
line=$(echo "$line" | sed -e "s,^~,$HOME," | sed -e "s,^\$HOME,$HOME," | xargs) # xargs for trimming outer spaces
if [ -d "$line" ] ; then debug12 "Found path $line ::prepending" ; PATH="$line:$PATH"
else debug12 "NOT found path $line" ; fi
done < "$PROFILES_CONFIG_DIR/Shell/path.prepend.txt"
# 2
debug12 "PREPENDING os-specific PATH ENTRIES ........"
[ -r "$PROFILES_CONFIG_DIR/Shell/path.$(uname).prepend.txt" ] && \
while IFS= read -r line &>/dev/null; do
line=$(echo "$line" | sed -e "s,^~,$HOME," | sed -e "s,^\$HOME,$HOME," | xargs)
if [ -d "$line" ] ; then debug12 "Found path $line ::prepending" ; PATH="$line:$PATH"
else debug12 "NOT found path $line" ; fi
done < "$PROFILES_CONFIG_DIR/Shell/path.$(uname).prepend.txt"
# 3
debug12 "PREPENDING architecture-specific PATH ENTRIES ........"
[ -r "$PROFILES_CONFIG_DIR/Shell/path.$(uname).$(uname -m).prepend.txt" ] && \
while IFS= read -r line &>/dev/null; do
line=$(echo "$line" | sed -e "s,^~,$HOME," | sed -e "s,^\$HOME,$HOME," | xargs)
if [ -d "$line" ] ; then debug12 "Found path $line ::prepending" ; PATH="$line:$PATH"
else debug12 "NOT found path $line" ; fi
done < "$PROFILES_CONFIG_DIR/Shell/path.$(uname).$(uname -m).prepend.txt"
# 4
debug12 "APPENDING global PATH ENTRIES ........"
[ -r "$PROFILES_CONFIG_DIR/Shell/path.append.txt" ] && \
while IFS= read -r line; do
line=$(echo "$line" | sed -e "s,^~,$HOME," | sed -e "s,^\$HOME,$HOME," | xargs)
if [ -d "$line" ] ; then debug12 "Found path $line ::appending" ; PATH="$PATH:$line"
else debug12 "NOT found path $line" ; fi
done < "$PROFILES_CONFIG_DIR/Shell/path.append.txt"
# 5
debug12 "APPENDING os-specific PATH ENTRIES ........"
[ -r "$PROFILES_CONFIG_DIR/Shell/path.$(uname).append.txt" ] && \
while IFS= read -r line; do
line=$(echo "$line" | sed -e "s,^~,$HOME," | sed -e "s,^\$HOME,$HOME," | xargs)
if [ -d "$line" ] ; then debug12 "Found path $line ::appending" ; PATH="$PATH:$line" ;
else debug12 "NOT found path $line" ; fi
done < "$PROFILES_CONFIG_DIR/Shell/path.$(uname).append.txt"
# 6
debug12 "APPENDING architecture-specific PATH ENTRIES ........"
[ -r "$PROFILES_CONFIG_DIR/Shell/path.$(uname).$(uname -m).append.txt" ] && \
while IFS= read -r line; do
line=$(echo "$line" | sed -e "s,^~,$HOME," | sed -e "s,^\$HOME,$HOME," | xargs)
if [ -d "$line" ] ; then debug12 "Found path $line ::apppending" ; PATH="$PATH:$line"
else debug12 "NOT found path $line" ; fi
done < "$PROFILES_CONFIG_DIR/Shell/path.$(uname).$(uname -m).append.txt"
debug12 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
}
# setupPath sets the path
function setupPath() {
debug8 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '...............................................'
local _POTENTIAL_DIR
# set up initial path
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
if [ "$UID" = 0 ] ; then
debug8 root PATH initialisation
PATH=/sbin:/usr/sbin:/bin:/usr/bin
fi
# add directories if existing for all platforms
setupPathsFromFiles
if [ -f "$HOME/.rbenv/version" ] ; then
debug "rbenv version file found"
ruby_version=$(cat "$HOME/.rbenv/version" | head -n 1)
debug " ruby_version is $ruby_version"
if [ -d "$HOME/.rbenv/versions/$ruby_version/bin" ] ; then
PATH="$HOME/.rbenv/versions/$ruby_version/bin:$PATH"
debug " adding path for ruby version $ruby_version"
else
echo " .rbenv/version file found with version $ruby_version, but appropriate directory with installation not found." &> /dev/stderr
fi
fi
debug8 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
}
# envVars set environment variables for all (sub-)shells
function envVars() {
debug8 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '...............................................'
export SHELL=$(which bash || errorExit 1 "bash could not be found") # fix for docker
export BASH_ENV=TRUE # tells bashrc that bash_profile was loaded
export LESS='-iR' # -i := searches are case insensitive;
# -R := Like -r, but only ANSI "color" escape sequences are output in "raw" form.
# The default is to display control characters using the caret notation.
export PAGER=less
export RSYNC_FLAGS="-rltDvu --modfiy-window=1" # Windows FS updates file-times only every 2nd second
export RSYNC_SLINK_FLAGS="$RSYNCFLAGS --copy-links" # copy s-links as files
export RSYNC_LINK='--copy-links'
export VISUAL=vim
export EDITOR="$VISUAL" # bsroot has no notion about VISUAL
export BLOCKSIZE=1K
export COLUMNS # required for diff2
export KUBECTL=kubectl
if which docker 2&>/dev/null ; then
export CONTAINER=docker
debug8 CONTAINER $CONTAINER
fi
if which podman 2&>/dev/null ; then
export CONTAINER=podman
debug8 CONTAINER $CONTAINER
alias docker=podman
fi
export BASH_SILENCE_DEPRECATION_WARNING=1 # OSX suppress bash warning
export LS_COLOUR='-G'
export LSCOLORS=Exfxcxdxbxegedabagacad # change directory colour 1st letter; see man ls(1)
export PROFILES_CONFIG_DIR=$(ls -l "$HOME/.bashrc" | awk '{ print $NF }' | xargs dirname)
[ -z "$PROFILES_CONFIG_DIR" ] && error PROFILES_CONFIG_DIR not set
debug8 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
}
function main() {
debug4 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '...............................................'
# seem to be inherited to sub-shells
set -o ignoreeof # prevent ^d logout
set -o noclobber # overwrite protection, use >| to force
envVars # load environment variables (above), required for PROFILES_CONFIG_DIR below, must be done after PATH setup
setupPath
# shellcheck source=/dev/null
[ -z "$NO_bashrc" ] && [ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc" # start all the normal files
# iterm @OSX
# shellcheck source=/dev/null
[ -r "$HOME/.iterm2_shell_integration.bash" ] && [ "$(uname)" = "Darwin" ] && source "$HOME/.iterm2_shell_integration.bash"
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
debug4 "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
}
# debugSet
debug "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '...............................................'
main "$@"
debug "${BASH_SOURCE[0]}::${FUNCNAME[0]}" '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
# EOF