-
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathsync-apps-data
More file actions
executable file
·83 lines (67 loc) · 1.86 KB
/
Copy pathsync-apps-data
File metadata and controls
executable file
·83 lines (67 loc) · 1.86 KB
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
#!/bin/bash
#
# Synchronize apps data with a custom local folder that I back up frequently to an external drive.
#
# - Run the synchronization:
#
# `sync-apps-data`
#
# ---
# Author: Nick Plekhanov, https://plekhanov.me
# License: MIT
# https://github.com/nicksp/dotfiles
set -eu
CYAN="$(tput setaf 6)"
UNDERLINE="$(tput sgr 0 1)"
RESET="$(tput sgr0)"
title() {
echo -e "${UNDERLINE}${CYAN}${1}${RESET}\n"
}
_bk() {
source_dir="$1"
dest_dir="$2"
backup_name="$3"
shift 3
exclude_names=("$@")
title "Backing up ${backup_name}…"
mkdir -p "$dest_dir"
should_exclude() {
item_name="$1"
for exclude_name in ${exclude_names[@]+"${exclude_names[@]}"}; do
if [ "$item_name" = "$exclude_name" ]; then
return 0
fi
done
return 1
}
# Remove any files/directories in the destination that are not in the source
for item in "$dest_dir"/*; do
item_name="$(basename "$item")"
if should_exclude "$item_name"; then
continue
fi
if [ ! -e "$source_dir/$item_name" ]; then
rm -rf "$item"
fi
done
# Copy files/directories from the source to the destination
for item in "$source_dir"/*; do
item_name="$(basename "$item")"
if should_exclude "$item_name"; then
continue
fi
if [ -d "$item" ]; then
cp -R "$item" "$dest_dir"
else
cp "$item" "$dest_dir"
fi
done
title "Done 🦜"
}
# Obsidian settings synchronization
OBSIDIAN_VAULT="$HOME/Library/Mobile Documents/iCloud~md~obsidian/Documents/Chest"
_bk "$OBSIDIAN_VAULT/.obsidian" "$HOME/dotfiles/obsidian/.obsidian" "Obsidian configs" "themes"
# Obsidian templates and bases synchronization
_bk "$OBSIDIAN_VAULT/99 🥒 Meta" "$HOME/dotfiles/obsidian/99 🥒 Meta" "Obsidian templates and bases"
# Obsidian notes/images synchronization
_bk "$OBSIDIAN_VAULT" "$HOME/Documents/MYDATA/Obsidian" "Obsidian vault content"