-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·48 lines (41 loc) · 860 Bytes
/
sync.sh
File metadata and controls
executable file
·48 lines (41 loc) · 860 Bytes
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
#!/usr/bin/env bash
# Script to sync dotfiles to home directory
cd "$(dirname "$0")"
# sync dotfiles from git/ and system/ to home directory
sync_dotfiles() {
local dry_run_flag=""
if [[ "$1" == "--dry-run" ]]; then
dry_run_flag="--dry-run"
echo "Dry run mode - showing what would be synced:"
echo
fi
rsync \
--exclude ".DS_Store" \
--archive \
--verbose \
${dry_run_flag} \
git/ system/ "$HOME"
}
# prompt user for confirmation
confirm_sync() {
read -p "This may overwrite existing files in your home directory. Are you sure? (y/n) " -n 1
echo
[[ $REPLY =~ ^[Yy]$ ]]
}
# main execution
main() {
case "$1" in
--force|-f)
sync_dotfiles
;;
--dry-run|-d)
sync_dotfiles --dry-run
;;
*)
if confirm_sync; then
sync_dotfiles
fi
;;
esac
}
main "$@"