-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·405 lines (332 loc) · 8.27 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
#!/usr/bin/env bash
# vim: fdm=marker
set -eu -o pipefail
# TODO: 絶対パスに変える?
current="$(cd -- "$(dirname -- "${BASH_SOURCE:-$0}")" && pwd)"
## Utils {{{
in_path(){
which "${@}" >/dev/null 2>&1
}
binln(){
local name rpath bname
[[ ! -d "${HOME}/bin" ]] && mkdir "${HOME}/bin"
for name in "${@}"; do
rpath="$(readlink -f "${name}")"
bname="$(basename "${name}")"
ln -svi "${rpath}" "${HOME}/bin/${bname%.*}"
done
}
sln(){
abs_src="$(readlink -f "${1:?src}")"
abs_dest="$(readlink -f "${2:?dest}")"
ln -svin "${abs_src}" "${abs_dest}"
}
dotln(){
local name
mkdir -p "${HOME}/bin"
for name in "${@}"; do
ln -svin "${name:a}" "${HOME}/.${name:t:r}"
done
}
get_linux_type(){
grep -Po '(?<=^ID\=).*|(?<=^ID_LIKE\=).*' /etc/os-release | tr -d '\n'
}
get_os_type(){
case "${OSTYPE:-}" in
linux*) get_linux_type ;;
darwin*) echo 'macos' ;;
esac
}
# }}}
mini(){
setup_dirs
setup_config_files
setup_zsh
setup_vim
install_peco
}
setup_dirs(){
mkdir -vpm 700 "${HOME}/bin"
mkdir -vpm 700 "${HOME}/.ssh"
mkdir -vpm 700 "${HOME}/.config"
mkdir -vpm 700 "${HOME}/.cache"
mkdir -vpm 700 "${HOME}/tmp"
mkdir -vpm 700 "${HOME}/works"
mkdir -vpm 700 "${HOME}/src"
mkdir -vpm 700 "${HOME}/codes"
}
setup_config_files(){
dir="${current}/rc/dots"
find "${dir}" | while read -r name; do
ln -svi "${dir}/${name}" "${HOME}/.$name"
done
dir="${current}/rc/config"
find "${dir}" | while read -r name; do
ln -svi "${dir}/${name}" "${HOME}/.config/"
done
# lesskey
}
setup_zsh(){
# link configs
ln -svi "${current}/zsh/zshenv" "${HOME}/.zshenv"
ln -svi "${current}/zsh/zshrc" "${HOME}/.zshrc"
mkdir -p "${HOME}/.zsh"
# create zshrc.local
touch "${current}/zsh/zshrc.local"
# zgen
git clone https://github.com/tarjoilija/zgen.git "${HOME}/.zgen"
zsh -ic 'exit'
if [[ ! ${SHELL:-} =~ '/zsh' ]]; then
echo 'Set zsh as default shell'
chsh -s "$(grep -m 1 zsh /etc/shells)"
fi
}
setup_vim(){
git clone https://github.com/uplus/vimrc "${HOME}/.vim"
# neovim
mkdir -p ~/.config
ln -svi "${HOME}/.vim" "${HOME}/.config/nvim"
mkdir -p "${HOME}/.vim/tmp"
install_dein
}
clone_myrepos_tmp(){
local ssh my_repo
echo -n " have you ssh-key of git?(y/N)"
read -rn 1 ssh
echo
if [[ $ssh =~ [yY] ]]; then
my_repo='[email protected]:uplus'
else
my_repo='https://github.com/uplus'
fi
git clone "${my_repo}/vimrc.git" "${HOME}/.vim/"
install_dein
git clone "${my_repo}/rbrn.git" "${HOME}/codes/rbrn"
}
# pkg_ {{{
pkg_go(){
pkgs=(
github.com/peco/peco/cmd/peco
github.com/peco/migemogrep
github.com/yudai/gotty
github.com/mikefarah/yq/v4 # jq for YAML
github.com/simeji/jid/cmd/jid # json incremental digger
github.com/google/yamlfmt/cmd/yamlfmt@latest
# github.com/motemen/gore # REPL
github.com/k0kubun/pp
# github.com/jstemmer/gotags
github.com/golang/lint/golang
golang.org/x/tools/cmd/gorename
golang.org/x/tools/cmd/goimports@latest
golang.org/x/tools/cmd/gotype
github.com/itchyny/bed/cmd/bed # binary editor
github.com/ichinaski/pxl # display images in the terminal
github.com/monochromegane/the_platinum_searcher/cmd/pt
github.com/rhysd/actionlint/cmd/actionlint@latest
)
for name in "${pkgs[@]}"; do
go install -v "${name}"
done
}
pkg_scala() {
pkgs=(
scalafix
metals
)
cs install "${pkgs[@]}"
}
pkg_pip(){
pkgs=(vim-vint ipython yamllint s-tui pynvim percol Send2Trash qmk pyls flake8 autopep8 termdown datadog)
pip3 install --upgrade --user --break-system-packages "${pkgs[@]}"
}
pkg_cargo(){
pkgs=(
eza
tealdeer
tree-sitter-cli
cargo-update
cargo-tree
cargo-asm # クレート::関数でディスアセンブル
cargo-script
# cargo-modules
fd-find
typos-cli
)
for name in "${pkgs[@]}"; do
cargo install "${name}"
done
tldr --update
}
pkg_npm(){
pkgs=(
pyright
typescript
typescript-language-server
js-beautify
)
for name in "${pkgs[@]}"; do
npm install -g "${name}"
done
}
pkg_gem(){
pkgs=(
# rdoc
yard
debug
irb
# neovim
# gist
# travis
solargraph
dip
rubocop
rubocop-performance
rubocop-rspec
# console, output
rb-readline
# color_echo
# awesome_print
# CLI utils like grep, sed, aws, etc..
pru
gemdiff
# Open a library file. gem {edit | open | browse | clone}
# https://github.com/tpope/gem-browse
gem-browse
# gitリポジトリからインストール
specific_install
# delete published gem
# gemcutter
# TUI filesystem explorer
rfd
# Simple SQL Linter
sqlint
# google-api-client
# octokit
# parser
# nokogiri
# mechanize
)
gem install "${pkgs[@]}"
}
pkg_brew(){
pkgs=(
# 標準のgitはなんか重い
git
ripgrep peco
gcc go rust
shellcheck lua-language-server
coreutils findutils iproute2mac luajit grep pgrep pkill watch
fswatch svn tig tree wget curl unzip tmux pwgen jq nkf deno libtool pkg-config gettext
automake cmake ctop direnv graphviz llvm ninja openssl@3 proctools qmk/qmk/qmk sshuttle yarn git-secrets
)
brew install "${pkgs[@]}"
brew install --cask alacritty alt-tab gimp homebrew/cask-fonts/font-source-code-pro homebrew/cask-fonts/font-source-code-pro-for-powerline
# brew install neovim --HEAD
# brew install --cask vagrant virtualbox
}
# }}}
# install_ {{{
install_echo_sd(){
wget https://raw.githubusercontent.com/fumiyas/home-commands/master/echo-sd -O ~/bin/echo-sd
chmod +x !$
}
install_ctop(){
wget https://github.com/bcicen/ctop/releases/download/v0.7.2/ctop-0.7.2-linux-amd64 -O ~/bin/ctop
chmod +x !$
}
install_dein(){
git clone --depth 1 https://github.com/Shougo/dein.vim ~/.cache/dein/repos/github.com/Shougo/dein.vim
}
install_peco(){
if in_path go; then
go get -u github.com/peco/peco/cmd/peco
else
install_peco_wget
fi
}
install_peco_wget(){
req_url='https://api.github.com/repos/peco/peco/releases'
target='peco_linux_amd64'
get_url="$(curl -sS "${req_url}" | grep 'browser_download_url' | grep "${target}" | head -1 | awk '$0=$2' | tr -d '"')"
wget "${get_url}" -O - | tar zxf -
mv "${target}/peco" "${HOME}/bin" && rm -r "${target}"
}
install_ripgrep(){
case "$(get_os_type)" in
'arch') sudo pacman -S ripgrep ;;
'macos') brew install ripgrep ;;
esac
}
install_qmk(){
pacman -S --no-confirm avr-gcc avr-libc dfu-util
yaourt -S --no-confirm dfu-programmer teensy-loader-cli
}
#}}}
# misc {{{
set_cap_nmap(){
sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service,cap_net_broadcast+eip /usr/bin/nmap
}
vul_env(){
docker pull citizenstig/dvwa
}
ime_vars(){
cat <<- END | sudo tee -a /etc/profile
export XIM_PROGRAM="fcitx"
export XIM="fcitx"
export XIM_ARGS="-d"
export GTK_IM_MODULE="fcitx"
export QT_IM_MODULE="fcitx"
export ECORE_IMF_MODULE="xim"
export XMODIFIERS="@im=fcitx"
END
}
disable_settings_daemon_keyboard(){
dconf write /org/gnome/settings-daemon/plugins/keyboard/active false
}
change_keymap(){
sudo ln -s "${current}/u10.xkb" /usr/share/X11/xkb/symbols/u10
sudo rm /var/lib/xkb/*
echo "
! option = symbols
u10:happy = +u10(happy)
u10:tenkey = +u10(tenkey)" | sudo tee -a /usr/share/X11/xkb/rules/evdev
dconf write /org/gnome/desktop/input-sources/xkb-options "['ctrl:nocaps', 'u10:happy', 'u10:tenkey']"
# $ setxkbmap -option ctrl:nocaps -option u10:happy -option u10:tenkey
}
#}}}
# TODO: つくる
get_pkg_manager(){
case "$(get_os_type)" in
*arch*)
alias a.i='sudo pacman -S --noconfirm'
alias a.u='sudo pacman -Syyu --noconfirm'
alias a.ud='sudo pacman -Syy'
;;
*debian*)
alias a.i='sudo apt-get install -y'
alias a.u='sudo apt-get update && sudo apt-get upgrade -y'
alias a.ud='sudo apt-get update'
;;
*fedora*)
if in_path dnf; then
alias a.i='sudo dnf install -y'
alias a.u='sudo dnf upgrade -y'
alias a.ud='sudo dnf upgrade -y'
else
alias a.i='sudo yum install -y'
alias a.u='sudo yum update -y'
alias a.ud='sudo yum update -y'
fi
;;
*)
echo 'cannot detect os' >&2
esac
}
help(){
grep -o "^[^ ]*()" "${current}/setup.sh" | sed "s/()//g"
}
if [ $# -eq 0 ]; then
help
else
$1 ;
fi