-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.sh
226 lines (213 loc) · 5.71 KB
/
config.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
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/sh
. $(pwd)/constants.sh
. $(pwd)/omz/themes.sh
. $(pwd)/omz/plugins.sh
git_config()
{
# Link config
if [ "$1" = "--link" ]; then
case $OS in
"Linux")
GIT_CONF="$HOME/.gitconfig"
if [ -f "$GIT_CONF" ]; then
sudo mv $GIT_CONF $HOME/.gitconfig.pre-config-run.$TIME
fi
ln -s $DOTFILES_CONF/.gitconfig $GIT_CONF
ls -l $DOTFILES_CONF/.gitconfig
;;
*)
# leave as is
return
;;
esac
fi
# Unlink config
if [ "$1" = "--unlink" ]; then
case $OS in
"Linux")
GIT_CONF="$HOME/.gitconfig"
unlink $GIT_CONF
;;
*)
# leave as is
return
;;
esac
fi
}
hyper_config()
{
HYPER_CONF="$HOME/.hyper.js"
# Link config
if [ "$1" = "--link" ]; then
case $OS in
"Linux")
if [ -f "$HYPER_CONF" ]; then
sudo mv $HYPER_CONF $HOME/.hyper.js.pre-config-run.$TIME
fi
ln -s $DOTFILES_CONF/.hyper.js $HYPER_CONF
ls -l $DOTFILES_CONF/.hyper.js
;;
*)
# leave as is
return
;;
esac
fi
# Unlink config
if [ "$1" = "--unlink" ]; then
case $OS in
"Linux")
unlink $HYPER_CONF
;;
*)
# leave as is
return
;;
esac
fi
}
zsh_config()
{
if [ "$1" = "--link" ]; then
case $OS in
"Linux")
ZSH_CONF="$HOME/.zshrc"
if [ -f "$ZSH_CONF" ]; then
sudo mv $ZSH_CONF $HOME/.zshrc.pre-config-run.$TIME
fi
ln -s $DOTFILES_CONF/.zshrc $ZSH_CONF
ls -l $DOTFILES_CONF/.zshrc
;;
*)
# leave as is
return
;;
esac
fi
if [ "$1" = "--unlink" ]; then
case $OS in
"Linux")
ZSH_CONF="$HOME/.zshrc"
unlink $ZSH_CONF
;;
*)
# leave as is
return
;;
esac
fi
}
omz_config()
{
# !BUG: Wakatime plugin is not cloning (Something to do with if condition $1 is not passed when called)
if [ "$1" = "--link" ]; then
case $OS in
"Linux")
OMZ_CUSTOM="$HOME/.oh-my-zsh/custom"
OMZ_CONF_ALIASES="$OMZ_CUSTOM/alias.zsh"
OMZ_CONF_FUNCTIONS="$OMZ_CUSTOM/functions.zsh"
if [ -f "$OMZ_CONF_ALIASES" ]; then
sudo mv $OMZ_CONF_ALIASES $OMZ_CUSTOM/alias.zsh.pre-config-run.$TIME
fi
if [ -f "$OMZ_CONF_FUNCTIONS" ]; then
sudo mv $OMZ_CONF_FUNCTIONS $OMZ_CUSTOM/functions.zsh.pre-config-run.$TIME
fi
# Create symlink for omz alias
ln -s $DOTFILES_CONF/.oh-my-zsh/custom/alias.zsh $OMZ_CONF_ALIASES
ls -l $OMZ_CONF_ALIASES
# Create symlink for omz functions
ln -s $DOTFILES_CONF/.oh-my-zsh/custom/alias.zsh $OMZ_CONF_FUNCTIONS
ls -l $OMZ_CONF_FUNCTIONS
# Clone omz plugins
printf "$GREEN Installing WakaTime plugin. $NC\n"
zsh_wakatime
printf "$GREEN Installing zsh_nvm plugin. $NC\n"
zsh_nvm
printf "$GREEN Installing autosuggestion plugin. $NC\n"
zsh_autosuggestions
printf "$GREEN Installing syntax highlighting plugin. $NC\n"
zsh_syntax_highlighting
;;
*)
# leave as is
return
;;
esac
fi
if [ "$1" = "--unlink" ]; then
case $OS in
"Linux")
OMZ_CUSTOM="$HOME/.oh-my-zsh/custom"
OMZ_CONF_ALIASES="$OMZ_CUSTOM/alias.zsh"
OMZ_CONF_FUNCTIONS="$OMZ_CUSTOM/functions.zsh"
unlink $OMZ_CONF_ALIASES
unlink $OMZ_CONF_FUNCTIONS
;;
*)
# leave as is
return
;;
esac
fi
}
# TODO Add any config option managed through this file.
list_help() {
printf "\n$YELLOW_HL Config options.$NC\n"
printf "$GREEN
--link or -l (To create symbolic link between config file on .dotfiles project and link location)\n
--unlink or -u (To remove created symbolic link)
$NC\n"
printf "$YELLOW_HL Following configurations are managed by the config.sh script.$NC\n"
printf "$GREEN
Git (Version control system),\n
Hyper.js (Terminal Emulator),\n
zsh (zsh shell configs),\n
omz (oh-my-zsh plugins and themes)\n
$NC\n"
}
main() {
# Parse Action
case $1 in
-l | --link)
action="--link"
;;
-u | --unlink)
action="--unlink"
;;
--help | *)
list_help
exit 0
;;
esac
action=$(echo $action | tr '[:upper:]' '[:lower:]')
# Parse config arguments
if [ $# -gt 1 ]; then
for args in "$@"; do
args=$(echo $args | tr '[:upper:]' '[:lower:]') # Change input to lowercase
case $args in
"git")
git_config $action
;;
"zsh")
zsh_config $action
;;
"omz")
omz_config $action
;;
"p10k")
p10k_config $action
;;
-l | --link | -u | --unlink | --help)
# do nothing it is parsed as action
;;
*)
printf "\n$RED Configuration instruction for \"$args\" dose not exist.$NC\n"
list_help
exit 1
;;
esac
done
fi
}
main $@