-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
249 lines (218 loc) · 5.11 KB
/
setup.sh
File metadata and controls
249 lines (218 loc) · 5.11 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/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
}
is_wsl() {
grep -qi microsoft /proc/version 2>/dev/null
}
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/apt.sh
source ./lib/asdf.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"
"ghostty-config .config/ghostty/config"
".hammerspoon .hammerspoon"
)
case ${OSTYPE} in
darwin*)
link_arr+=(
".hammerspoon .hammerspoon"
)
;;
*)
;;
esac
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
case ${OSTYPE} in
darwin*)
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}
;;
*)
;;
esac
# 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)
}
suggest_missing_gitconfig_files() {
gitconfig_file="${DOT_DIRECTORY}/.gitconfig"
[ ! -f "${gitconfig_file}" ] && return
include_paths=()
while IFS= read -r path; do
[ -z "${path}" ] && continue
include_paths+=("${path}")
done < <(awk -F'=' '/^[[:space:]]*path[[:space:]]*=/{
gsub(/^[[:space:]]+|[[:space:]]+$/, "", $2)
print $2
}' "${gitconfig_file}")
[ ${#include_paths[@]} -eq 0 ] && return
missing_files=()
for path in "${include_paths[@]}"; do
if [[ "${path}" == ~* ]]; then
target_path="${path/#\~/${HOME}}"
elif [[ "${path}" == /* ]]; then
target_path="${path}"
else
target_path="${HOME}/${path}"
fi
[ -f "${target_path}" ] || missing_files+=("${target_path}")
done
if [ ${#missing_files[@]} -gt 0 ]; then
echo "$(tput setaf 3)Suggestion: Create the following gitconfig include file(s) for GitHub email switching:$(tput sgr0)"
for missing in "${missing_files[@]}"; do
echo " - ${missing}"
done
echo " ex) cat > ${HOME}/.gitconfig.user <<'EOF'"
echo " [user]"
echo " name = your.name"
echo " email = your.email@example.com"
echo " EOF"
fi
}
initialize() {
# ignore shell execution error temporarily
set +e
case ${OSTYPE} in
darwin*)
run_brew
run_asdf
;;
linux*)
run_apt
run_brew
run_asdf
;;
*)
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
case ${OSTYPE} in
darwin*)
run_gnu_gcc
;;
*)
;;
esac
echo "$(tput setaf 2)Initialize complete!. ✔︎$(tput sgr0)"
}
update() {
if has "brew"; then
brew bundle dump -f
else
echo "$(tput setaf 1)brew not found; skipping update$(tput sgr0)"
fi
}
command=$1
[ $# -gt 0 ] && shift
case $command in
deploy)
link_files
suggest_missing_gitconfig_files
;;
init*)
initialize
;;
update)
update
;;
*)
usage
;;
esac
exit 0