-
Notifications
You must be signed in to change notification settings - Fork 32
/
deploy.zsh
executable file
·115 lines (102 loc) · 2.12 KB
/
deploy.zsh
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
#!/usr/bin/env zsh
set -e
files=($(git ls-files | egrep -v 'backup|.ssh|proxy.pac.coffee|weechat'))
target=~
LN_OPT=-sf
[[ $(uname) =~ Linux && $(ln --version) =~ coreutils ]] && LN_OPT=-sfr
declare -A dir
dir[.vim]=1
#dir[.emacs.d/private/+my]=1
dir[.config/doom]=1
info() {
printf "\e[1;36m$*\e[m\n"
}
action() {
printf "\e[1;32m$*\e[m\n"
}
warning() {
printf "\e[1;33m$*\e[m\n"
}
link() {
ln "$LN_OPT" "$PWD/$1" "$2"
}
do_ssh() {
#cp -auT home/.ssh ~/.ssh
if [[ -d ~/.ssh ]]; then
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
fi
}
do_mkdir() {
[[ -f ~/.history ]] && rm -i ~/.history
mkdir -p ~/{.history,tmp}
mkdir -p ~/.vimtmp/{backup,swap,undo}
mkdir -p ~/Wallpapers ~/.local/opt
}
do_git() {
git submodule update --init --recursive
mkdir -p ~/.vim/bundle
if [[ ! -d ~/.vim/bundle/vim-plug ]]; then
git clone https://github.com/junegunn/vim-plug ~/.vim/bundle/vim-plug
fi
}
do_mkdir
do_ssh
do_git
for f in "${(@k)dir[@]}"; do
g="$target/${f/home\//}"
mkdir -p "${g%/*}"
if ! [[ -L "$g" ]]; then
if [[ -e "$g" ]]; then
action "$g exists"
continue
fi
link "home/$f" "$g"
fi
done
for f in ${files[@]}; do
if [[ "$f" =~ ^home/ ]]; then
ff=${f/home\//}
skip=
while :; do
[[ ${dir[$ff]+_} ]] && skip=1
[[ $ff =~ / ]] || break
ff=${ff%/*}
done
[[ -n $skip ]] && continue
else
continue
fi
info "Copying $f"
g="$target/${f/home\//}"
mkdir -p "${g%/*}"
if ! [[ -L "$g" ]]; then
if [[ -f "$g" || "$f" -ot "$g" ]]; then
if diff -q "$f" "$g"; then
action "identical $g"
continue
else
diff -u "$g" "$f" | less -FMX
while :; do
warning "Overwrite $g ?\n(y)es (n)o (m) vim -d (q)uit [y/n/m/q]"
read -rs 'option?Option: '
case $option in
[ny])
break;;
m)
vim -d "$g" "$f";;
q)
exit;;
*)
continue;;
esac
done
if [[ $option == n ]]; then
action "skipping $g"
continue
fi
fi
fi
link "$f" "$g"
fi
done