-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·105 lines (88 loc) · 3.01 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
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
#!/bin/bash
################################################################
#
# Helper functions
# Credit: https://github.com/mjacobus/.dotfiles
#
################################################################
function ask_should_symlink() {
while true; do
read -p "Do you want to symlink $1 to $2 ? " yn
case $yn in
[Yy]*)
symlink_safe $1 $2
break
;;
[Nn]*) return ;;
*) echo "Please answer yes or no." ;;
esac
done
}
function symlink_or_ask() {
if [ -L $2 ]; then
echo "$1 is already linked to $2"
elif [ -d $2 ]; then
ask_should_symlink $1 $2
elif [ -f $2 ]; then
ask_should_symlink $1 $2
else
ln -s $1 $2
fi
}
function backup_move() {
SCRIPT_TIME=$(date +%Y%m%d%H_%M_%S)
mv $1 "${1}_${SCRIPT_TIME}"
}
function symlink_safe() {
echo "symlinking $1 to $2"
if [ -f $2 ]; then
backup_move $2 && ln -sf $1 $2
else
ln -sf $1 $2
fi
}
#----------------------------------------------------------------
# Initial setup
#----------------------------------------------------------------
mkdir -p ~/.config
#----------------------------------------------------------------
# Shell
#----------------------------------------------------------------
# bash config
symlink_or_ask ~/.dotfiles/dots/.bashrc ~/.bashrc
symlink_or_ask ~/.dotfiles/dots/.bash_profile ~/.bash_profile
symlink_or_ask ~/.dotfiles/dots/.bash_aliases ~/.bash_aliases
symlink_or_ask ~/.dotfiles/dots/.bash_colors ~/.bash_colors
# git shell completion
if [ ! -f ~/.git-completion.bash ]; then
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
fi
#----------------------------------------------------------------
# Git
#----------------------------------------------------------------
symlink_or_ask ~/.dotfiles/dots/.gitconfig ~/.gitconfig
symlink_or_ask ~/.dotfiles/dots/.gitignore.global ~/.gitignore.global
#----------------------------------------------------------------
# Vim + Neovim
#----------------------------------------------------------------
# vim config
symlink_or_ask ~/.dotfiles/dots/.vim ~/.vim
symlink_or_ask ~/.dotfiles/dots/.vimrc ~/.vimrc
symlink_or_ask ~/.dotfiles/dots/.config/nvim ~/.config/nvim
symlink_or_ask ~/.vim/coc-settings.json ~/.config/nvim/coc-settings.json
# install vim-plug
if [ ! -d ~/.dotfiles/editor/vim/autoload/plug.vim ]; then
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
vim +PlugInstall +qall
fi
#----------------------------------------------------------------
# Misc
#----------------------------------------------------------------
symlink_or_ask ~/.dotfiles/dots/.config/bat ~/.config/bat
symlink_or_ask ~/.dotfiles/dots/.config/karabiner ~/.config/karabiner
symlink_or_ask ~/.dotfiles/dots/.config/phpactor ~/.config/phpactor
symlink_or_ask ~/.dotfiles/dots/.config/ranger ~/.config/ranger
symlink_or_ask ~/.dotfiles/dots/.config/wezterm ~/.config/wezterm
symlink_or_ask ~/.dotfiles/dots/.config/zed ~/.config/zed
symlink_or_ask ~/.dotfiles/dots/.kenv ~/.kenv