-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.sh
executable file
·82 lines (73 loc) · 2.22 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
#!/bin/bash
base_dir=$(cd "$(dirname "$0")" && pwd)
backup_dir="$base_dir/.backups.local"
backup_prefix="$backup_dir/$(date '+%Y%m%d%H%M%S')"
link_file() {
local src=$1 dst=$2
local backup_dst=false delete_dst=false link_dst=true
if [[ -e $dst ]]; then
current_link=$(readlink "$dst")
if [[ "$current_link" != "$src" ]]; then
while true; do
printf "File already exists: %s. What do you want?\n" "$dst"
printf "[r]eplace; [b]ack up; [s]kip: "
read -r op
case $op in
r )
delete_dst=true
link_dst=true
break;;
b )
backup_dst=true
delete_dst=true
link_dst=true
break;;
s )
link_dst=false
break;;
* )
echo "Unrecognized option: $op";;
esac
done
else
echo "$dst is already linked to $src"
link_dst=false
fi
fi
if [[ "$backup_dst" == "true" ]]; then
mkdir -p "$backup_dir"
local backup_file
backup_file="$backup_prefix$(basename "$dst")"
mv "$dst" "$backup_file"
echo "$dst was backed up to $backup_file"
fi
if [[ "$delete_dst" == "true" ]]; then
rm -rf "$dst"
fi
if [[ "$link_dst" == "true" ]]; then
ln -s "$src" "$dst"
echo "Linked $dst to $src"
return 0
fi
return 1
}
echo "Setting up zsh..."
link_file "$base_dir/zsh/zshrc" ~/.zshrc
echo "Setting up neovim..."
mkdir -p ~/.config
link_file "$base_dir/nvim" ~/.config/nvim
echo "Setting up vim..."
if link_file "$base_dir/vim/vimrc" ~/.vimrc ; then
vim +PlugInstall +qall
fi
echo "Setting up tmux..."
link_file "$base_dir/tmux" ~/.config/tmux
if [[ `uname` == "Darwin" ]]; then
echo "Setting up Hammerspoon..."
link_file "$base_dir/hammerspoon" ~/.hammerspoon
fi
echo "Setting up git..."
link_file "$base_dir/git" ~/.config/git
echo "Setting up WezTerm..."
link_file "$base_dir/wezterm" ~/.config/wezterm
echo "Done"