forked from ohmybash/oh-my-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoh-my-bash.bash
175 lines (153 loc) · 5.73 KB
/
oh-my-bash.bash
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
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
# Error handling
## if {einfo,warn,die}() are not set globally (so that end-user can customize the error) then sets script's definitions
if ! command -v einfo > /dev/null; then einfo() { printf "INFO: %s\n" "$1" 1>&2 ; } fi
if ! command -v warn > /dev/null; then warn() { printf "WARN: %s\n" "$1" 1>&2 ; } fi
if ! command -v die > /dev/null; then die() {
case $1 in
# FALSE
1) printf "FATAL: %s\n" "$2" 1>&2 ; exit $1 ;;
# Custom
*) (printf "FATAL: Syntax error $([ -n "${FUNCNAME[0]}" ] && printf "in ${FUNCNAME[0]}")\n%s\n" "$2" 1>&2 ; exit "$1") || (printf "FATAL: %s\n" "$1" 1>&2 ; exit $1)
esac
} fi
# Bail out early if non-interactive
[[ $- != *i* ]] && die 1 "Shell is not interactive"
# Check for updates on initial load...
if ! ((DISABLE_AUTO_UPDATE)) ; then
env OSH="$OSH" DISABLE_UPDATE_PROMPT="$DISABLE_UPDATE_PROMPT" bash -f "${OSH}/tools/check_for_upgrade.bash"
fi
# Initializes Oh My Bash
# add a function path
fpath=("${OSH}/functions" "$fpath")
# Set OSH_CUSTOM to the path where your custom config files
# and plugins exists, or else we will use the default custom/
if [[ -z "$OSH_CUSTOM" ]]; then
OSH_CUSTOM="${OSH}/custom"
fi
# Set OSH_CACHE_DIR to the path where cache files should be created
# or else we will use the default cache/
if [[ -z "$OSH_CACHE_DIR" ]]; then
OSH_CACHE_DIR="${OSH}/cache"
fi
# Load all of the config files in ~/.oh-my-bash/lib that end in .bash
# TIP: Add files you don't want in git to .gitignore
for config_file in ${OSH}/lib/*.bash; do
custom_config_file="${OSH_CUSTOM}/lib/${config_file:t}"
[ -f "${custom_config_file}" ] && config_file="${custom_config_file}"
source "$config_file"
done
is_plugin() {
local base_dir="$1"
local name="$2"
[[ -f "${base_dir}/plugins/${name}/{${name}.plugin.bash,_${name}}" ]]
}
# Add all defined plugins to fpath. This must be done
# before running compinit.
for plugin in ${plugins[@]}; do
if is_plugin "$OSH_CUSTOM" "$plugin"; then
fpath=("${OSH_CUSTOM}/plugins/$plugin" "$fpath")
elif is_plugin $OSH $plugin; then
fpath=("${OSH}/plugins/$plugin" "$fpath")
fi
done
is_completion() {
local base_dir="$1"
local name="$2"
[ -f "${base_dir}/completions/${name}/${name}.completion.bash" ]
}
# Add all defined completions to fpath. This must be done
# before running compinit.
for completion in "${completions[@]}"; do
if is_completion "$OSH_CUSTOM" "$completion"; then
fpath=(${OSH_CUSTOM}/completions/${completion} $fpath)
elif is_completion "$OSH" "$completion"; then
fpath=("${OSH}/completions/${completion}" "$fpath")
fi
done
is_alias() {
local base_dir="$1"
local name="$2"
[ -f "${base_dir}/aliases/${name}/${name}.aliases.bash" ]
}
# Add all defined completions to fpath. This must be done
# before running compinit.
for alias in "${aliases[@]}"; do
if is_alias "$OSH_CUSTOM" "$alias"; then
fpath=("${OSH_CUSTOM}/aliases/$alias" "$fpath")
elif is_alias "$OSH" "$alias"; then
fpath=("${OSH}/aliases/$alias" "$fpath")
fi
done
# Figure out the SHORT hostname
if [[ $(uname) == Darwin* ]]; then
# macOS's $HOST changes with dhcp, etc. Use ComputerName if possible.
SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
else
SHORT_HOST="${HOST/.*/}"
fi
# Load all of the plugins that were defined in ~/.bashrc
for plugin in ${plugins[@]}; do
if [ -f "${OSH_CUSTOM}/plugins/${plugin}/${plugin}.plugin.bash" ]; then
source "${OSH_CUSTOM}/plugins/${plugin}/${plugin}.plugin.bash"
elif [ -f "${OSH}/plugins/${plugin}/${plugin}.plugin.bash" ]; then
source "${OSH}/plugins/${plugin}/${plugin}.plugin.bash"
fi
done
# Load all of the aliases that were defined in ~/.bashrc
for alias in "${aliases[@]}"; do
if [ -f "${OSH_CUSTOM}/aliases/${alias}.aliases.bash" ]; then
source "${OSH_CUSTOM}/aliases/${alias}.aliases.bash"
elif [ -f "${OSH}/aliases/${alias}.aliases.bash" ]; then
source "${OSH}/aliases/${alias}.aliases.bash"
fi
done
# Load all of the completions that were defined in ~/.bashrc
for completion in ${completions[@]}; do
if [ -f "${OSH_CUSTOM}/completions/$completion.completion.bash" ]; then
source "${OSH_CUSTOM}/completions/$completion.completion.bash"
elif [ -f "${OSH}/completions/$completion.completion.bash" ]; then
source "${OSH}/completions/$completion.completion.bash"
fi
done
# Load all of your custom configurations from custom/
for config_file in "${OSH_CUSTOM}/*.bash"; do
if [ -f "$config_file" ]; then
source "$config_file"
fi
done
unset config_file
# Load colors first so they can be use in base theme
source "${OSH}/themes/colours.theme.bash"
source "${OSH}/themes/base.theme.bash"
# Load the theme
if [ "$OSH_THEME" = "random" ]; then
themes=("${OSH}/themes/*/*theme.bash")
N=${#themes[@]}
((N=(RANDOM%N)))
RANDOM_THEME="${themes[$N]}"
source "$RANDOM_THEME"
echo "[oh-my-bash] Random theme '$RANDOM_THEME' loaded..."
else
if [ -n "$OSH_THEME" ]; then
if [ -f "${OSH_CUSTOM}/$OSH_THEME/$OSH_THEME.theme.bash" ]; then
source "${OSH_CUSTOM}/$OSH_THEME/$OSH_THEME.theme.bash"
# https://github.com/ohmybash/oh-my-bash/issues/70
elif [ -f "$OSH_CUSTOM/themes/$OSH_THEME/${OSH_THEME}-bash.theme.sh" ]; then
source "$OSH_CUSTOM/themes/$OSH_THEME/${OSH_THEME}-bash.theme.sh"
elif [ -f "${OSH_CUSTOM}/themes/$OSH_THEME/$OSH_THEME.theme.bash" ]; then
source "${OSH_CUSTOM}/themes/$OSH_THEME/$OSH_THEME.theme.bash"
else
source "${OSH}/themes/$OSH_THEME/$OSH_THEME.theme.bash"
fi
fi
fi
if [[ $PROMPT ]]; then
export PS1="\["$PROMPT"\]"
fi
if ! type_exists '__git_ps1' ; then
source "${OSH}/tools/git-prompt.bash"
fi
# Adding Support for other OSes
[ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview" ||
[ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app" || PREVIEW="less"