-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
169 lines (145 loc) · 3.34 KB
/
setup.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
#!/bin/bash
set -e
OS="$(uname -s)"
DOT_DIRECTORY="${HOME}/dotfiles"
DOT_TARBALL="https://github.com/yoskeoka/dotfiles/tarball/master"
REMOTE_URL="https://github.com/yoskeoka/dotfiles.git"
has() {
type "$1" > /dev/null 2>&1
}
usage() {
name=`basename $0`
cat <<EOF
Usage:
$name [arguments] [command]
Commands:
deploy [-f]
initialize
update
Arguments:
-f $(tput setaf 1)** warning **$(tput sgr0) Overwrite dotfiles.
-h Print help (this message)
EOF
exit 1
}
while getopts "fh" opt; do
case ${opt} in
f)
OVERWRITE=true
;;
h)
usage
;;
esac
done
shift $((OPTIND - 1))
# If the dotfiles directory missing, download and extract the dotfiles repository
if [ ! -d ${DOT_DIRECTORY} ]; then
echo "Downloading dotfiles..."
mkdir ${DOT_DIRECTORY}
if has "git"; then
git clone --depth 1 --recursive "${REMOTE_URL}" "${DOT_DIRECTORY}"
else
curl -fsSLo ${HOME}/dotfiles.tar.gz ${DOT_TARBALL}
tar -zxf ${HOME}/dotfiles.tar.gz --strip-components 1 -C ${DOT_DIRECTORY}
rm -f ${HOME}/dotfiles.tar.gz
fi
echo $(tput setaf 2)Download dotfiles complete!. ✔︎$(tput sgr0)
fi
cd ${DOT_DIRECTORY}
source ./lib/brew.sh
source ./lib/zsh.sh
source ./lib/fisher.sh
source ./lib/pip.sh
source ./lib/go.sh
source ./lib/rust.sh
source ./lib/npm.sh
source ./lib/yarn.sh
source ./lib/gnu_gcc.sh
link_files() {
for f in .??*
do
# If you have ignore files, add file/directory name here
[[ ${f} = ".git" ]] && continue
[[ ${f} = ".gitignore" ]] && continue
[[ ${f} = ".editorconfig" ]] && continue
# Force remove the file if it's already there
[ -n "${OVERWRITE}" -a -e ${HOME}/${f} ] && rm -f ${HOME}/${f}
if [ ! -e ${HOME}/${f} ]; then
ln -snfv ${DOT_DIRECTORY}/${f} ${HOME}/${f}
fi
done
link_arr=(
# dotfiles/{$src} {$HOME}/{$dest}
"config.fish .config/fish/config.fish"
"starship.toml .config/starship.toml"
"kitty.conf .config/kitty/kitty.conf"
# ".hammerspoon .hammerspoon"
)
for link in "${link_arr[@]}"
do
IFS=' ' read -r src dest <<< $link
echo "$src -> $dest"
[ -n "${OVERWRITE}" -a -e ${HOME}/${dest} ] && rm -f ${HOME}/${dest}
mkdir -p $(dirname ${HOME}/${dest})
ln -snfv ${DOT_DIRECTORY}/${src} ${HOME}/${dest}
done
## karabiner.json
conf_dest=".config/karabiner/karabiner.json"
conf_src="karabiner.json"
[ -n "${OVERWRITE}" -a -e ${HOME}/${conf_dest} ] && rm -f ${HOME}/${conf_dest}
mkdir -p $(dirname ${HOME}/${conf_dest})
cp ${DOT_DIRECTORY}/${conf_src} ${HOME}/${conf_dest}
# OS dependent
case ${OSTYPE} in
darwin*)
mkdir -p ${HOME}/Library/Preferences
ln -snfv ${DOT_DIRECTORY}/acc ${HOME}/Library/Preferences/atcoder-cli-nodejs
;;
*)
;;
esac
echo $(tput setaf 2)Deploy dotfiles complete!. ✔︎$(tput sgr0)
}
initialize() {
# ignore shell execution error temporarily
set +e
case ${OSTYPE} in
darwin*)
run_brew
;;
*)
echo $(tput setaf 1)Working only OSX$(tput sgr0)
exit 1
;;
esac
run_zsh
run_fisher
run_pip
run_go
run_rust
run_npm
run_yarn
run_gnu_gcc
echo "$(tput setaf 2)Initialize complete!. ✔︎$(tput sgr0)"
}
update() {
brew bundle dump -f
}
command=$1
[ $# -gt 0 ] && shift
case $command in
deploy)
link_files
;;
init*)
initialize
;;
update)
update
;;
*)
usage
;;
esac
exit 0