-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·63 lines (56 loc) · 1.24 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
#!/bin/bash
set -eu
COMMON_MKDIR_PATHS=(
".config/nvim"
".zsh.d"
)
COMMON_COPY_FILES=(
".zshrc"
)
COMMON_LINK_FILES=(
".config/nvim/dein.toml"
".config/nvim/init.vim"
".gitconfig"
".gitignore-rkmathi"
".Xresources"
".zsh.d/zsh-syntax-highlighting"
)
function goto_error() {
cat << EOS
Usage:
$ ./install.sh -[Environment]
Environment:
-l : Linux
-m : macOS
-w : Windows
EOS
exit 1
}
function install_common_files() {
for path in ${COMMON_MKDIR_PATHS[@]}; do mkdir -p ${HOME}/${path}; done
for file in ${COMMON_COPY_FILES[@]}; do cp -afv $(pwd)/${file} ${HOME}/${file}; done
for file in ${COMMON_LINK_FILES[@]}; do ln -fsv $(pwd)/${file} ${HOME}/${file}; done
}
function link_env_file() {
basename=$(echo ${1} | awk -F'/' '{print $NF}')
ln -fsv $(pwd)/${1} ${HOME}/${basename}
}
function install_env_files() {
for file in envs/${1}/.*; do
if [[ ! ${file} =~ \/\.{1,2}$ ]]; then link_env_file ${file}; fi
done
}
env_type=""
while getopts ":lmw" opts; do
case ${opts} in
l ) env_type="linux";;
m ) env_type="mac";;
w ) env_type="win";;
\? ) goto_error;;
esac
done
shift $(expr ${OPTIND} - 1)
if [ -z ${env_type} ]; then goto_error; fi
install_common_files
install_env_files ${env_type}
echo "OK"