forked from Bash-it/bash-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·140 lines (129 loc) · 3.55 KB
/
install.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
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
#!/usr/bin/env bash
BASH_IT="$HOME/.bash_it"
case $OSTYPE in
darwin*)
CONFIG_FILE=.bash_profile
;;
*)
CONFIG_FILE=.bashrc
;;
esac
BACKUP_FILE=$CONFIG_FILE.bak
if [ -e $HOME/$BACKUP_FILE ]; then
echo "Backup file already exists. Make sure to backup your .bashrc before running this installation." >&2
read -s -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file [y/N] " RESP
while true
do
case $RESP in
[yY])
break
;;
[nN]|"")
echo "Installation aborted. Please come back soon!"
exit 1
;;
*)
echo -e "\033[91mUnknown choice. Please choose y or N.\033[m"
read -s -n 1 -p " " RESP
continue
;;
esac
done
fi
test -w $HOME/$CONFIG_FILE &&
cp -a $HOME/$CONFIG_FILE $HOME/$CONFIG_FILE.bak &&
echo "Your original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak"
cp $HOME/.bash_it/template/bash_profile.template.bash $HOME/$CONFIG_FILE
echo "Copied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it"
function load_all() {
file_type=$1
[ ! -d "$BASH_IT/$file_type/enabled" ] && mkdir "$BASH_IT/${file_type}/enabled"
for src in $BASH_IT/${file_type}/available/*; do
filename="$(basename ${src})"
[ ${filename:0:1} = "_" ] && continue
dest="${BASH_IT}/${file_type}/enabled/${filename}"
if [ ! -e "${dest}" ]; then
ln -s "../available/${filename}" "${dest}"
else
echo "File ${dest} exists, skipping"
fi
done
}
function load_some() {
file_type=$1
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
for path in `ls $BASH_IT/${file_type}/available/[^_]*`
do
file_name=$(basename "$path")
while true; do
read -s -n 1 -p "Would you like to enable the ${file_name%%.*} $file_type? [y/N] " RESP
case $RESP in
[yY])
echo "Y"
ln -s "../available/${file_name}" "$BASH_IT/$file_type/enabled"
break
;;
[nN]|"")
echo "N"
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
done
}
if [[ "$1" == "--none" ]]
then
echo "Not enabling any aliases, plugins or completions"
elif [[ "$1" == "--all" ]]
then
echo "Enabling all aliases, plugins and completions."
load_all aliases
load_all plugins
load_all completion
else
while true
do
read -p "Do you use Jekyll? (If you don't know what Jekyll is, answer 'n') [Y/N] " RESP
case $RESP in
[yY])
cp $HOME/.bash_it/template/jekyllconfig.template.bash $HOME/.jekyllconfig
echo "Copied the template .jekyllconfig into your home directory. Edit this file to customize bash-it for using the Jekyll plugins"
break
;;
[nN])
break
;;
*)
echo "Please enter Y or N"
esac
done
for type in "aliases" "plugins" "completion"
do
while true
do
read -p "Would you like to enable all, some, or no $type? Some of these may make bash slower to start up (especially completion). (all/some/none) " RESP
case $RESP
in
some)
load_some $type
break
;;
all)
load_all $type
break
;;
none)
break
;;
*)
echo "Unknown choice. Please enter some, all, or none"
continue
;;
esac
done
done
echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
fi