-
Notifications
You must be signed in to change notification settings - Fork 1
/
bash_profile.sh
86 lines (68 loc) · 2.87 KB
/
bash_profile.sh
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
#!/bin/bash
###############################################################################
# bash_profile.sh
#
# if you only want certain functionality, you can source a file individually, if you
# want everything, then you source this file and it will worry about sourcing all the
# other files. If you do source a file separately be warned it might have a dependency
# on something else that won't be in the environment, so the safest way is just to
# source this file and take everything
#
# but to get everything:
#
# . bash_profile.sh
###############################################################################
# autodiscover the directory if it isn't already set
if [[ -z "$DOTBASH_DIR" ]]; then
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
function getBashDir(){
src="${BASH_SOURCE[0]}"
while [ -h "$src" ]; do # resolve $source until the file is no longer a symlink
dir="$( cd -P "$( dirname "$src" )" && pwd )"
src="$(readlink "$src")"
# if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
[[ $src != /* ]] && src="$dir/$src"
done
dir="$( cd -P "$( dirname "$src" )" && pwd )"
echo "$dir"
}
export DOTBASH_DIR=getBashDir
fi
export DOTBASH_INCLUDE_DIR=$DOTBASH_DIR/include
export DOTBASH_PROFILE_DIR=$DOTBASH_DIR/profile.d
export DOTBASH_BIN_DIR=$DOTBASH_DIR/bin
# add our bin file to the end of path
for di in $(find "$DOTBASH_BIN_DIR" -type d); do
#echo $di
export PATH="$PATH:$di"
done
#export PATH="$PATH:$DOTBASH_BIN_DIR"
#export PATH="$PATH:$DOTBASH_BIN_DIR/search"
#export PATH="$PATH:$DOTBASH_BIN_DIR/ssh"
# source all the environment files
for fi in $(find "$DOTBASH_PROFILE_DIR" -name "*.sh"); do
#echo "$fi"
#sr=$(python -c "import time; print(time.time())")
source "$fi"
#echo "Took $(python -c "import time; print(time.time() - $sr)") to load $fi"
done
###############################################################################
# readline - configure readline using the inputrc file and the ~/.inputrc file if available
###############################################################################
# http://www.softpanorama.org/Scripting/Shellorama/inputrc.shtml
# http://unix.stackexchange.com/questions/27471/setting-readline-variables-in-the-shell
#base_dot_bash_dir=$(dirname "${BASH_SOURCE[0]}")
base_dot_bash_dir=$DOTBASH_DIR
# first we source our file
if [[ -f "$base_dot_bash_dir/inputrc" ]]; then
# echo "binding $base_dot_bash_dir/inputrc"
bind -f "$base_dot_bash_dir/inputrc"
fi
# then we source our custom user file
if [[ -f "$HOME/.inputrc" ]]; then
# echo "binding $HOME/.inputrc"
bind -f "$HOME/.inputrc"
fi
# only show directories when you tab after `cd`
# https://unix.stackexchange.com/questions/186422/
complete -d cd