Repository navigation
Expand file tree
/
Copy pathmklinks
More file actions
executable file
·118 lines (102 loc) · 3 KB
/
Copy pathmklinks
File metadata and controls
executable file
·118 lines (102 loc) · 3 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
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
114
115
116
117
118
#!/usr/bin/env bash
set -euo pipefail
# resolve the repo root from the script's own location so it works from any clone
DOTDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONF="${XDG_CONFIG_HOME:-$HOME/.config}"
STATE="${XDG_STATE_HOME:-$HOME/.local/state}"
DATA="${XDG_DATA_HOME:-$HOME/.local/share}"
BIN="$HOME/.local/bin"
APPLICATIONS="$DATA/applications"
# mirrors install.sh, which skips desktop-only packages on WSL (see README)
is_wsl() {
if [ -n "${WSL_DISTRO_NAME:-}" ]; then
return 0
fi
grep -qiE '(microsoft|wsl)' /proc/version 2>/dev/null
}
# dotfiles under .config that only make sense with a desktop session
desktop_only() {
case "$1" in
ghostty|hypr|quickshell|zathura) return 0 ;;
*) return 1 ;;
esac
}
if is_wsl; then
WSL=true
else
WSL=false
fi
mklink() {
local target=$1
local link=$2
local name="$(basename "$link")"
if [ -L "$link" ]; then
# if a symlink is broken from an old/moved path,
# or simply the wrong target, repoint it
if [ "$(readlink "$link")" = "$target" ]; then
echo " ok $name"
return
fi
echo " relink $name"
ln -sfn "$target" "$link"
elif [ -e "$link" ]; then
echo " skip $name (already exists and is not a symlink)"
else
echo " link $name"
ln -s "$target" "$link"
fi
}
echo "Symlinking dotfiles from $DOTDIR"
echo
if [ "$WSL" = true ]; then
echo "WSL detected: desktop-only entries will be skipped"
echo
fi
mkdir -p "$CONF" "$BIN" "$STATE"
echo "configs -> $CONF"
for entry in "$DOTDIR/.config/"*; do
[ -e "$entry" ] || continue # check if the path exists, otherwise skip
name="$(basename "$entry")"
if [ "$WSL" = true ] && desktop_only "$name"; then
echo " skip $name"
continue
fi
mklink "$entry" "$CONF/$name"
done
echo
echo "scripts -> $BIN"
for script in "$DOTDIR/.local/bin/"*; do
[ -f "$script" ] || continue # check if it's actually a file, otherwise skip
chmod +x "$script"
mklink "$script" "$BIN/$(basename "$script")"
done
echo
echo "state -> $STATE"
for entry in "$DOTDIR/.local/state/"*; do
[ -e "$entry" ] || continue # check if the path exists, otherwise skip
mklink "$entry" "$STATE/$(basename "$entry")"
done
echo
echo "applications -> $APPLICATIONS"
if [ "$WSL" = true ]; then
echo " skip applications (desktop only)"
else
mkdir -p "$APPLICATIONS"
for entry in "$DOTDIR/.local/share/applications/"*; do
[ -e "$entry" ] || continue # check if the path exists, otherwise skip
mklink "$entry" "$APPLICATIONS/$(basename "$entry")"
done
fi
echo
echo "themes -> $DATA/themes"
if [ "$WSL" = true ]; then
echo " skip themes (desktop only)"
else
mkdir -p "$DATA/themes"
for entry in "$DOTDIR/.local/share/themes/"*; do
[ -e "$entry" ] || continue # check if the path exists, otherwise skip
mklink "$entry" "$DATA/themes/$(basename "$entry")"
done
fi
echo
echo "Done."