-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·39 lines (33 loc) · 1.26 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·39 lines (33 loc) · 1.26 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
#!/usr/bin/env bash
# Define an array of source and destination file pairs
FILES=(
# "$HOME/path/to/source/file1:~/path/to/destination/file1"
# "$HOME/path/to/source/file2:~/path/to/destination/file2"
"$HOME/.bashrc:./.bashrc"
"$HOME/.bash_profile:./.bash_profile"
"$HOME/.zshrc:./.zshrc"
"/etc/nixos/configuration.nix:./nixos/configuration.nix"
"/etc/nixos/hardware-configuration.nix:./nixos/hardware-configuration.nix"
"/etc/nixos/flake.nix:./nixos/flake.nix"
"/etc/nixos/flake.lock:./nixos/flake.lock"
"$HOME/.config/tmux/tmux.conf:./.config/tmux/tmux.conf"
"$HOME/.config/nvim/init.vim:./.config/nvim/init.vim"
"$HOME/.config/starship.toml:./.config/starship.toml"
# Add more file pairs as needed
)
# Iterate through the file pairs and sync each one
for PAIR in "${FILES[@]}"; do
SOURCE_FILE="${PAIR%%:*}"
DEST_FILE="${PAIR##*:}"
# Expand the tilde in the destination file path
# DEST_FILE="${DEST_FILE/#\~/$HOME}"
# Sync from SOURCE to DEST if the source is newer
if [ "$SOURCE_FILE" -nt "$DEST_FILE" ]; then
rsync -avu "$SOURCE_FILE" "$DEST_FILE"
fi
# Sync from DEST to SOURCE if the destination is newer
if [ "$DEST_FILE" -nt "$SOURCE_FILE" ]; then
rsync -avu "$DEST_FILE" "$SOURCE_FILE"
fi
done
echo "Two-way sync complete."