Repository navigation
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·87 lines (74 loc) · 3.01 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·87 lines (74 loc) · 3.01 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
84
85
86
87
#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_DIR="$REPO_DIR/dotfiles"
TARGET_USER="${SUDO_USER:-$USER}"
TARGET_HOME="$(getent passwd "$TARGET_USER" 2>/dev/null | cut -d: -f6)"
TARGET_HOME="${TARGET_HOME:-$HOME}"
CONFIG_DIR="${XDG_CONFIG_HOME:-$TARGET_HOME/.config}"
echo ":: Checking and synchronizing configs from $CONFIG_DIR to $REPO_DIR..."
sync_component() {
local name="$1"
local config_path="$CONFIG_DIR/$name"
local repo_path="$DOTFILES_DIR/$name"
if [ ! -e "$config_path" ]; then
echo " [SKIP] $config_path does not exist."
return
fi
# Check if already a symlink pointing to our repo
if [ -L "$config_path" ]; then
local target
target="$(readlink -f "$config_path" 2>/dev/null || true)"
local expected
expected="$(readlink -f "$repo_path" 2>/dev/null || true)"
if [ "$target" = "$expected" ]; then
echo " [OK] $name is already symlinked to repository (live-synced)."
return
fi
fi
echo " -> $name is not symlinked to repository, importing changes..."
mkdir -p "$repo_path"
case "$name" in
hypr)
rsync -av "$config_path/" "$repo_path/"
sed -i -E "s|path = /home/[^/]+/\.config/hypr/|path = ~/.config/hypr/|g" "$repo_path/hyprpaper.conf" "$repo_path/hyprlock.conf" 2>/dev/null || true
;;
quickshell)
rsync -av \
--exclude '.git' \
--exclude '*.log' \
--exclude '__pycache__' \
--exclude 'debug_pwd.txt' \
"$config_path/" "$repo_path/"
;;
wofi)
cp -a "$config_path/"* "$repo_path/" 2>/dev/null || true
sed -i -E 's|background-image:.*wofi/logo\.png.*|background-image: url("logo.png");|g' "$repo_path/style.css" 2>/dev/null || true
sed -i -E 's|stylesheet=[^ ]*wofi/style\.css|stylesheet=style.css|g' "$repo_path/config" 2>/dev/null || true
;;
fastfetch)
cp -a "$config_path/config.jsonc" "$repo_path/" 2>/dev/null || true
cp -a "$config_path/eye.png" "$repo_path/" 2>/dev/null || true
;;
fish)
mkdir -p "$repo_path/functions"
cp -a "$config_path/config.fish" "$repo_path/" 2>/dev/null || true
if [ -d "$config_path/functions" ]; then
cp -a "$config_path/functions/"* "$repo_path/functions/" 2>/dev/null || true
fi
;;
micro)
cp -a "$config_path/settings.json" "$repo_path/" 2>/dev/null || true
cp -a "$config_path/bindings.json" "$repo_path/" 2>/dev/null || true
;;
*)
cp -a "$config_path/"* "$repo_path/" 2>/dev/null || true
;;
esac
echo " re-linking $config_path -> $repo_path"
ln -sfn "$repo_path" "$config_path"
}
for dir in hypr quickshell wofi fastfetch fish micro; do
sync_component "$dir"
done
echo ":: Synchronization complete."