-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·218 lines (187 loc) · 5.25 KB
/
setup
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
#!/bin/bash
help()
{
echo "Environment setup helper"
echo ""
echo "Commands:"
echo "-h --help print help"
echo ""
echo "Environment:"
echo "-d --dev init dev environment variable"
echo "-o --home init home environment variable"
echo "-m --monitor-env init environment variables for controlling monitor output at ~/.config."
echo " It copies content of the files: '.config/monitor-environment' and '.config/xprofile-variables'."
echo ""
echo "Configs:"
echo "-b --bash init .bashrc and .bash_profile"
echo "-v --vim init .config/nvim and .ideavimrc"
echo "-g --git init .gitconfig"
echo "-i --i3wm init i3/config and configs for i3status and polybar"
echo "-t --other init .dircolors.256"
echo "-x --xmonad init Xmonad config"
echo "-a --alacritty init .config/alacritty/alacritty.yml"
echo "-u --tmux init .config/tmux/tmux.conf"
echo "-r --rofi init .config/rofi/config.rasi"
}
initEnvironmentVariable()
{
# create file "~/.config/environment"
environment=$1
echo -e "ENV=\"$environment\"" > "$HOME/.config/environment"
}
createLink()
{
src=$1
dst=$2
successMessage="Successfully created link to: $PWD/$src"
errorMessage="Failed to create link to: $HOME/$src"
if [ -f "$HOME/$dst" ]; then
rm "$HOME/$dst" && ln -s "$PWD/$src" "$HOME/$dst" && echo "$successMessage" || echo "$errorMessage"
elif [ -d "$HOME/$dst" ]; then
rm "$HOME/$dst" && ln -s "$PWD/$src" "$HOME/$dst" && echo "$successMessage" || echo "$errorMessage"
else
ln -s "$PWD/$src" "$HOME/$dst" && echo "$successMessage" || echo "$errorMessage"
fi
}
initBash()
{
createLink ".bashrc" ".bashrc"
createLink ".bash_profile" ".bash_profile"
}
initVim()
{
# i3 config
createLink ".config/nvim" ".config/nvim"
# Create link to IdeaVim plugin config file
createLink ".ideavimrc" ".ideavimrc"
}
initGit()
{
env=$(getEnvironmentVariable)
createLink "$env/.gitconfig" ".gitconfig"
}
initAlacritty()
{
env=$(getEnvironmentVariable)
createDirIfNeed ".config/alacritty"
createLink "$env/.config/alacritty/alacritty.yml" ".config/alacritty/alacritty.yml"
}
initTmux()
{
env=$(getEnvironmentVariable)
createDirIfNeed ".config/tmux"
createLink "$env/.config/tmux/tmux.conf" ".config/tmux/tmux.conf"
}
initI3wm()
{
# i3 config
createLink ".config/i3" ".config/i3"
# picom config
createLink ".config/picom" ".config/picom"
# polybar config
createLink ".config/polybar" ".config/polybar"
}
initXmonad()
{
env=$(getEnvironmentVariable)
# Create necessary dirs
createDirIfNeed ".xmonad"
# Create links to config files
createLink ".xmonad/xmonad.hs" ".xmonad/xmonad.hs"
createLink ".xmonad/xmobar.hs" ".xmonad/xmobar.hs"
createLink ".xmonad/get-volume.sh" ".xmonad/get-volume.sh"
}
initRofi()
{
# Create necessary dirs
createDirIfNeed ".config/rofi"
# Create links to config files
createLink ".config/rofi/config.rasi" ".config/rofi/config.rasi"
}
createDirIfNeed()
{
name=$1
if [ ! -d "$HOME/$name" ]; then
mkdir "$HOME/$name" || echo "Failed to create directory: $HOME/$name"
fi
}
copyOrOverwrite()
{
src=$1
dst=$2
echo "Overwriting file: $src -> $dst"
cp -rf "$src" "$dst"
}
initOther()
{
createLink ".dircolors.256" ".dircolors.256"
}
getEnvironmentVariable()
{
# read and return value of $ENV from environment file
errorMessage="Failed to determine environment variable ENV"
[ -f "$HOME/.config/environment" ] && grep "ENV" "$HOME/.config/environment" | cut -f2 -d"\"" || echo "$errorMessage"
}
initMonitorEnvironment()
{
env=$(getEnvironmentVariable)
if [ -f "$env/.config/monitor-environment" ]; then
copyOrOverwrite "$env/.config/monitor-environment" "$HOME/.config/monitor-environment"
fi
if [ -f "$env/.config/xprofile-variables" ]; then
copyOrOverwrite "$env/.config/xprofile-variables" "$HOME/.config/xprofile-variables"
fi
}
[[ "$1" == "" ]] && help
while [ "$1" != "" ]; do
PARAM=`echo $1 | awk -F= '{print $1}'`
VALUE=`echo $1 | awk -F= '{print $2}'`
case $PARAM in
-h | --help)
help
exit
;;
-d | --dev)
initEnvironmentVariable "dev"
;;
-o | --home)
initEnvironmentVariable "home"
;;
-b | --bash)
initBash
;;
-v | --vim)
initVim
;;
-g | --git)
initGit
;;
-i | --i3wm)
initI3wm
;;
-t | --other)
initOther
;;
-x | --xmonad)
initXmonad
;;
-m | --monitor-env)
initMonitorEnvironment
;;
-a | --alacritty)
initAlacritty
;;
-u | --tmux)
initTmux
;;
-r | --rofi)
initRofi
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
help
exit 1
;;
esac
shift
done