-
Notifications
You must be signed in to change notification settings - Fork 1
/
sync
executable file
·92 lines (74 loc) · 2.05 KB
/
sync
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
#!/bin/sh
dot="$(cd "$0/.." && pwd)"
tmp=$(mktemp -d); trap "rm -r $tmp" EXIT
dir=$tmp/dir
sym=$tmp/sym
vim=$tmp/vim
git="$(for cfg in attributes config; do echo "-o -name .git$cfg"; done)"
cd "$HOME"
sync()
{
if ! insync_dir; then
comm -13z $dir/actual $dir/expect \
| xargs -0r -n1 mkdir -pv | sed "s:^.\+ ':created ':"
fi
if ! insync_sym; then
comm -23z $sym/actual $sym/expect \
| cut -d: -f1 -z | xargs -0r rm -fv
comm -13z $sym/actual $sym/expect \
| cut -d: -f2 -z | xargs -0r -n1 ln -sv | sed "s:^'./:linked ':"
fi
if ! insync_vim; then
test -t 1 && printf '%s' "syncing '.vim/bundle/' ..."
vim +PluginClean! +PluginInstall +qa -esu "$dot/.vimrc"
test -t 1 && printf '\r\e[K'
printf '%s\n' "synced '.vim/bundle/'"
fi
}
reset()
{
git -C "$dot" clean -dffX .vim/bundle \
| awk '$1 == "Removing" { print "removed \x27" $2 "\x27" }'
insync_sym
cat $sym/actual | cut -d: -f1 -z | xargs -0r rm -fv
}
check()
{
insync_dir && insync_sym && insync_vim
}
insync_dir()
{
which vim > /dev/null || return 0
mkdir $dir
for sub in swap temp undo; do printf %s\\0 .cache/vim/$sub; done \
| sort -z > $dir/expect
find .cache/vim -maxdepth 1 -mindepth 1 -type d -print0 2> /dev/null \
| sort -z > $dir/actual
diff $dir/actual $dir/expect > /dev/null
}
insync_sym()
{
mkdir $sym
find . -mindepth 1 -prune \
-type l -lname "${dot#$HOME/}/*" \
-printf '%f:%l\0' | sort -z > $sym/actual
find "${dot#$HOME/}" -mindepth 1 -prune \
\( -name '.*' ! -name '.git*' $git \) \
-printf '%f:%p\0' | sort -z > $sym/expect
diff $sym/actual $sym/expect > /dev/null
}
insync_vim()
{
which vim > /dev/null || return 0
mkdir $vim
vim +PluginList +%p +qa -esu "$dot/.vimrc" \
| awk -F "[/']" '$3 { print $3 }' | sort > $vim/expect
find "$dot/.vim/bundle" -mindepth 1 -prune \
-type d -printf '%f\n' | sort > $vim/actual
diff $vim/actual $vim/expect > /dev/null
}
cmd="${1:-sync}"
case "$cmd" in
check|reset|sync) $cmd ;;
*) printf '%s\n' 'invalid subcommand'; exit 1 ;;
esac