2
2
# bash-it installer
3
3
4
4
# Show how to use this installer
5
- function _bash-it_show_usage () {
5
+ function _bash-it-install-help () {
6
6
echo -e " \n$0 : Install bash-it"
7
7
echo -e " Usage:\n$0 [arguments] \n"
8
8
echo " Arguments:"
@@ -15,83 +15,63 @@ function _bash-it_show_usage() {
15
15
exit 0
16
16
}
17
17
18
- # enable a thing
19
- function _bash-it_load_one() {
20
- file_type=$1
21
- file_to_enable=$2
22
- mkdir -p " $BASH_IT /${file_type} /enabled"
23
-
24
- dest=" ${BASH_IT} /${file_type} /enabled/${file_to_enable} "
25
- if [ ! -e " ${dest} " ]; then
26
- ln -sf " ../available/${file_to_enable} " " ${dest} "
27
- else
28
- echo " File ${dest} exists, skipping"
29
- fi
30
- }
31
-
32
18
# Interactively enable several things
33
- function _bash-it_load_some() {
19
+ function _bash-it-install-enable() {
20
+ local file_type single_type enable_func file_name just_the_name RESP
34
21
file_type=$1
35
22
single_type=$( echo " $file_type " | sed -e " s/aliases$/alias/g" | sed -e " s/plugins$/plugin/g" )
36
23
enable_func=" _enable-$single_type "
37
- [ -d " $BASH_IT /$file_type /enabled" ] || mkdir " $BASH_IT /$file_type /enabled"
38
- for path in " $BASH_IT /${file_type} /available/" [^_]* ; do
39
- file_name=$( basename " $path " )
24
+ for path in " ${BASH_IT?} /${file_type} /available/" [^_]* ; do
25
+ file_name=" ${path##*/ } "
40
26
while true ; do
41
- just_the_name=" ${file_name%% . * } "
27
+ just_the_name=" ${file_name% . ${file_type} .bash } "
42
28
read -r -e -n 1 -p " Would you like to enable the $just_the_name $file_type ? [y/N] " RESP
43
29
case $RESP in
44
30
[yY])
45
- $enable_func " $just_the_name "
31
+ " $enable_func " " $just_the_name "
46
32
break
47
33
;;
48
34
[nN] | " " )
49
35
break
50
36
;;
51
37
* )
52
- echo -e " \033[91mPlease choose y or n.\033[m "
38
+ echo -e " ${echo_orange :- } Please choose y or n.${echo_normal :- } "
53
39
;;
54
40
esac
55
41
done
56
42
done
57
43
}
58
44
59
45
# Back up existing profile
60
- function _bash-it_backup () {
61
- test -w " $HOME / $ CONFIG_FILE" \
62
- && cp -aL " $HOME / $ CONFIG_FILE" " $HOME / $ CONFIG_FILE .bak" \
63
- && echo -e " \033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE .bak\033[0m "
46
+ function _bash-it-install-backup-config () {
47
+ test -w " ${ HOME?} / ${ CONFIG_FILE?} " \
48
+ && cp -aL " ${ HOME?} / ${ CONFIG_FILE?} " " ${ HOME?} / ${ CONFIG_FILE?} .bak" \
49
+ && echo -e " ${echo_green :- } Your original ${ CONFIG_FILE?} has been backed up to ${ CONFIG_FILE?} .bak${echo_normal :- } "
64
50
}
65
51
66
52
# Back up existing profile and create new one for bash-it
67
- function _bash-it_backup_new () {
68
- _bash-it_backup
69
- sed " s|{{BASH_IT}}|$BASH_IT |" " $BASH_IT /template/bash_profile .template.bash" > " $HOME / $ CONFIG_FILE"
70
- echo -e " \033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE , edit this file to customize bash-it\033[0m "
53
+ function _bash-it-install-backup-new () {
54
+ _bash-it-install-backup-config
55
+ sed " s|{{BASH_IT}}|${ BASH_IT?} |" " ${ BASH_IT?} /template/bashrc .template.bash" > " ${ HOME?} / ${ CONFIG_FILE?} "
56
+ echo -e " ${echo_green :- } Copied the template ${ CONFIG_FILE?} into ~/${ CONFIG_FILE?} , edit this file to customize bash-it${echo_normal :- } "
71
57
}
72
58
73
59
# Back up existing profile and append bash-it templates at the end
74
- function _bash-it_backup_append() {
75
- local profile_strings=(' if [[ -f ~/.profile ]]; then' ' source ~/.profile' ' fi' ' if [[ -f ~/.bashrc ]]; then' ' source ~/.bashrc' ' fi' )
76
- _bash-it_backup
77
- (sed " s|{{BASH_IT}}|$BASH_IT |" " $BASH_IT /template/bash_profile.template.bash" | tail -n +2) >> " $HOME /$CONFIG_FILE "
78
- if [[ ! -f ~ /.bash_profile ]]; then
79
- printf ' %s\n\t%s\n%s\n%s\n\t%s\n%s\n' " ${profile_strings[@]} " > ~ /.bash_profile
80
- else
81
- printf ' \e[0;33m%s\n\t%s\n\t\t%s\n\t%s\n\t%s\n\t\t%s\n\t%s\n\e[0m' " You may need to update your ~/.bash_profile (or ~/.profile) to source your ~/.bashrc:" " ${profile_strings[@]} "
82
- fi
83
- echo -e " \033[0;32mBash-it template has been added to your $CONFIG_FILE \033[0m"
60
+ function _bash-it-install-backup-append() {
61
+ _bash-it-install-backup-config
62
+ (sed " s|{{BASH_IT}}|${BASH_IT?} |" " ${BASH_IT?} /template/bashrc.template.bash" | tail -n +2) >> " ${HOME?} /${CONFIG_FILE?} "
63
+ echo -e " ${echo_green:- } Bash-it template has been added to your ${CONFIG_FILE?}${echo_normal:- } "
84
64
}
85
65
86
- function _bash-it_check_for_backup () {
87
- if ! [[ -e " $HOME /$BACKUP_FILE " ]]; then
66
+ function _bash-it-install-backup-check () {
67
+ if ! [[ -e " ${ HOME?} /$BACKUP_FILE " ]]; then
88
68
return
89
69
fi
90
- echo -e " \033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m " >&2
70
+ echo -e " ${echo_yellow :- } Backup file already exists. Make sure to backup your .bashrc before running this installation.${echo_normal :- } " >&2
91
71
92
72
if [[ -z " ${overwrite_backup} " ]]; then
93
73
while [[ -z " ${silent} " ]]; do
94
- read -e -n 1 -r -p " Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME /$BACKUP_FILE ) [y/N] " RESP
74
+ read -e -n 1 -r -p " Would you like to overwrite the existing backup? This will delete your existing backup file (${ HOME?} /$BACKUP_FILE ) [y/N] " RESP
95
75
case $RESP in
96
76
[yY])
97
77
overwrite_backup=true
@@ -101,28 +81,28 @@ function _bash-it_check_for_backup() {
101
81
break
102
82
;;
103
83
* )
104
- echo -e " \033[91mPlease choose y or n.\033[m "
84
+ echo -e " ${echo_orange :- } Please choose y or n.${echo_normal :- } "
105
85
;;
106
86
esac
107
87
done
108
88
fi
109
89
if [[ -z " ${overwrite_backup} " ]]; then
110
- echo -e " \033[91mInstallation aborted. Please come back soon!\033[m "
90
+ echo -e " ${echo_orange :- } Installation aborted. Please come back soon!${echo_normal :- } "
111
91
if [[ -n " ${silent} " ]]; then
112
- echo -e " \033[91mUse \" -f\" flag to force overwrite of backup.\033[m "
92
+ echo -e " ${echo_orange :- } Use \" -f\" flag to force overwrite of backup.${echo_normal :- } "
113
93
fi
114
94
exit 1
115
95
else
116
- echo -e " \033[0;32mOverwriting backup...\033[m "
96
+ echo -e " ${echo_green :- } Overwriting backup...${echo_normal :- } "
117
97
fi
118
98
}
119
99
120
- function _bash-it_modify_config_files () {
121
- _bash-it_check_for_backup
100
+ function _bash-it-install-modify-config () {
101
+ _bash-it-install-backup-check
122
102
123
103
if [[ -z " ${silent} " ]]; then
124
104
while [[ -z " ${append_to_config} " ]]; do
125
- read -e -n 1 -r -p " Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
105
+ read -e -n 1 -r -p " Would you like to keep your ${ CONFIG_FILE?} and append bash-it templates at the end? [y/N] " choice
126
106
case $choice in
127
107
[yY])
128
108
append_to_config=true
@@ -132,17 +112,24 @@ function _bash-it_modify_config_files() {
132
112
break
133
113
;;
134
114
* )
135
- echo -e " \033[91mPlease choose y or n.\033[m "
115
+ echo -e " ${echo_orange :- } Please choose y or n.${echo_normal :- } "
136
116
;;
137
117
esac
138
118
done
139
119
fi
140
- if [[ -n " ${append_to_config} " ]]; then
120
+ if [[ -n " ${append_to_config:- } " ]]; then
141
121
# backup/append
142
- _bash-it_backup_append
122
+ _bash-it-install-backup-append
143
123
else
144
124
# backup/new by default
145
- _bash-it_backup_new
125
+ _bash-it-install-backup-new
126
+ fi
127
+ local choice profile_string=$' if [[ -s ~/.profile ]]; then\n\t source ~/.profile\n fi\n if [[ -s ~/.bashrc ]]; then\n\t source ~/.bashrc\n fi'
128
+ if [[ ! -f ~ /.bash_profile ]]; then
129
+ printf ' %s\n' " ${profile_string} " > ~ /.bash_profile
130
+ else
131
+ printf " ${echo_yellow:- } %s${echo_normal:- } " " You may need to update your ~/.bash_profile (or ~/.profile) to source your ~/.bashrc:"
132
+ printf ' %s\n' " ${profile_string} "
146
133
fi
147
134
}
148
135
@@ -163,7 +150,7 @@ OPTIND=1
163
150
while getopts " hsinaf" opt; do
164
151
case " $opt " in
165
152
" h" )
166
- _bash-it_show_usage
153
+ _bash-it-install-help
167
154
exit 0
168
155
;;
169
156
" s" ) silent=true ;;
@@ -172,7 +159,7 @@ while getopts "hsinaf" opt; do
172
159
" a" ) append_to_config=true ;;
173
160
" f" ) overwrite_backup=true ;;
174
161
" ?" )
175
- _bash-it_show_usage >&2
162
+ _bash-it-install-help >&2
176
163
exit 1
177
164
;;
178
165
esac
@@ -181,52 +168,53 @@ done
181
168
shift $(( OPTIND - 1 ))
182
169
183
170
if [[ -n " ${silent} " && -n " ${interactive} " ]]; then
184
- echo -e " \033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m "
171
+ echo -e " ${echo_orange :- } Options --silent and --interactive are mutually exclusive. Please choose one or the other.${echo_normal :- } "
185
172
exit 1
186
173
fi
187
174
188
175
if [[ -n " ${no_modify_config} " && -n " ${append_to_config} " ]]; then
189
- echo -e " \033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m "
176
+ echo -e " ${echo_orange :- } Options --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.${echo_normal :- } "
190
177
exit 1
191
178
fi
192
179
193
180
BASH_IT=" $( cd " ${BASH_SOURCE%/* } " && pwd) "
194
181
195
- CONFIG_FILE=.bashrc
182
+ CONFIG_FILE=" .bashrc"
196
183
197
- BACKUP_FILE=$ CONFIG_FILE .bak
184
+ BACKUP_FILE=" ${ CONFIG_FILE?} .bak"
198
185
echo " Installing bash-it"
199
186
if [[ -z " ${no_modify_config} " ]]; then
200
- _bash-it_modify_config_files
187
+ _bash-it-install-modify-config
201
188
fi
202
189
203
190
# Disable auto-reload in case its enabled
204
191
export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=' '
205
192
# Load dependencies for enabling components
206
- # shellcheck disable=SC1090
193
+ # shellcheck source-path=SCRIPTPATH/vendor/github.com/erichs/composure
207
194
source " ${BASH_IT} /vendor/github.com/erichs/composure/composure.sh"
208
195
cite _about _param _example _group _author _version
209
196
# shellcheck source-path=SCRIPTDIR/lib
210
- source " $BASH_IT /lib/utilities.bash"
211
- # shellcheck source-path=SCRIPTDIR/lib
212
197
source " ${BASH_IT} /lib/log.bash"
213
198
# shellcheck source-path=SCRIPTDIR/lib
214
- source " $BASH_IT /lib/helpers.bash"
199
+ source " ${BASH_IT?} /lib/utilities.bash"
200
+ # shellcheck source-path=SCRIPTDIR/lib
201
+ source " ${BASH_IT?} /lib/helpers.bash"
202
+ # shellcheck source-path=SCRIPTDIR/themes
203
+ source " ${BASH_IT?} /themes/colors.theme.bash"
215
204
216
205
if [[ -n $interactive && -z " ${silent} " ]]; then
217
206
for type in " aliases" " plugins" " completion" ; do
218
- echo -e " \033[0;32mEnabling ${type} \033[0m "
219
- _bash-it_load_some " $type "
207
+ echo -e " ${echo_green :- } Enabling ${type}${echo_normal :- } "
208
+ _bash-it-install-enable " $type "
220
209
done
221
210
else
222
211
echo " "
223
212
_bash-it-profile-load " default"
224
213
fi
225
214
226
215
echo " "
227
- echo -e " \033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
228
- # shellcheck disable=SC2086
229
- echo -e " \033[0;32mTo start using it, open a new tab or 'source " ~/$CONFIG_FILE " '.\033[0m"
216
+ echo -e " ${echo_green:- } Installation finished successfully! Enjoy bash-it!${echo_normal:- } "
217
+ echo -e " ${echo_green:- } To start using it, open a new tab or 'source ~/${CONFIG_FILE?} '.${echo_normal:- } "
230
218
echo " "
231
219
echo " To show the available aliases/completions/plugins, type one of the following:"
232
220
echo " bash-it show aliases"
0 commit comments