-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbkp-sync.sh
114 lines (95 loc) · 2.37 KB
/
bkp-sync.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
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
#
# Copies files from my dotfiles repository several places
# on $HOME.
#
# Assumes rsync is installed.
#
# On Arch Linux:
#
# pacman -S rsync --needed
#
# TODO: create a setup_emacs function as well since I also use emacs.
#
function usage() {
cat << EOF
Usage: ${0%/*} --sync|--dry-run
OPTIONS:
--sync, -s Really copy files to their destination.
--dry-run, -d Only pretend to see what would be copied.
--setup-vim Install Plug and run PlugIntall.
WARNING:
Running this script with the '--sync' option will pottentially override
files. So, know what you are doing. No backups will be made.
Consider running with '--dry-run' before really going for '--sync'.
You have been warned!
EOF
exit 0
}
function mkdirs () {
# Used for vim tmp/bkp files.
mkdir --verbose --parents ~/Temp/vim_{tmp,bkp}
mkdir --verbose --parents ~/.config/Code/User
}
#
# Clone plug.vim into vim's autoload directory. You can use
# this from time to time to fetch newer versions of Plug
# and make Plug update its managed plugins as well.
#
function setup_vim () {
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
vim -c 'PlugInstall'
}
#
# Takes on argument which is either --sync or --dry-run.
#
function sync () {
case "$1" in
--sync)
mkdirs
dryrun=''
;;
--dry-run)
dryrun=--dry-run
;;
*)
usage
;;
esac
# If '$dryrun' is empty, rsync will __really_ copy files.
# If it is '--dry-run', rsync will only pretend.
rsync \
"$dryrun" \
--filter='- .git/' \
--filter='- sync.sh' \
--filter='- README.md' \
--filter='- tmp_vim/' \
--filter='- tmp/' \
--filter='- bin/' \
--filter='- imgs/' \
--filter='- bash_incl/' \
--filter='- .config/Code' \
--filter='- .config/Code/User' \
--filter='- .config/Code/User/settings.json' \
--archive \
--no-perms \
--verbose \
--human-readable \
--itemize-changes \
./ ~/
}
case "$1" in
--sync|-s)
sync --sync
;;
--dry-run|-d)
sync --dry-run
;;
--setup-vim)
setup_vim
;;
*)
usage
;;
esac