-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·77 lines (66 loc) · 1.79 KB
/
bootstrap.sh
File metadata and controls
executable file
·77 lines (66 loc) · 1.79 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
#!/bin/sh
dir=$(cd $(dirname $0) && pwd)
# detect bash | zsh
is_bash() {
# $SHELL 環境変数で判定(より確実)
case "$SHELL" in
*/bash|*/bash.exe)
true
;;
*)
false
;;
esac
}
download_git_completion() {
curl -o git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh
}
deploy_git_completion() {
mkdir -p ~/.zsh && cd $_
if [ ! -e git-prompt.sh ] && [ ! -e git-completion.sh ] && [ ! -e _git ]; then
download_git_completion
fi
}
create_homedir_symlink() {
local basepath="$dir/$1"
if [ -z "$basepath" ]; then
return
fi
# 第2引数で出力ファイル名変更可能
local outname="$2"
if [ -z "$outname" ]; then
local outname="$1"
fi
local outpath="$HOME/$outname"
if [ -e "$outpath" ]; then
return
fi
ln -sfnv "$basepath" "$outpath"
}
install_dotfiles() {
if is_bash; then
create_homedir_symlink .profile .bash_profile
create_homedir_symlink .bashrc
else
create_homedir_symlink .profile .zprofile
create_homedir_symlink .zshrc
fi
for dotfile in "$dir"/.??*
do
local filename=$(basename "$dotfile")
[ "$filename" = ".git" ] && continue
[ "$filename" = ".profile" ] && continue
[ "$filename" = ".bashrc" ] && continue
[ "$filename" = ".zshrc" ] && continue
create_homedir_symlink "$filename"
done
}
# enable `code` command
# cat << EOF >> ~/.zprofile
# # Add Visual Studio Code (code)
# export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
# EOF
install_dotfiles
deploy_git_completion