- Only files are symlinked, not directories - Symlinks are created in target config dirs, not inside repo - Target dirs are checked and cleaned if symlinks - Removes wlogout config and device-specific repo symlinks - Updates .zshrc and wp-vol for robustness 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <noreply@opencode.ai>
119 lines
4.5 KiB
Bash
Executable File
119 lines
4.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# =====================
|
|
# Dotfiles Symlinking Script
|
|
# =====================
|
|
# - Symlinks all dotfiles and app configs from the repo to $HOME and $HOME/.config
|
|
# - Handles device-specific fragments for Hyprland, Waybar, etc. using $DOTFILES_DEVICE and $HOSTNAME
|
|
# - Idempotent and safe to re-run
|
|
# - To extend, add new fragment types to the fragment_types array below
|
|
# =====================
|
|
|
|
mkdir -p "$HOME/.config"
|
|
|
|
echo "Symlinking dotfiles..."
|
|
# Get the dotfiles directory (parent of modules directory)
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
DOTFILES_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
# Symlink regular dotfiles (excluding .config directory)
|
|
for file in $(find "$DOTFILES_DIR" -maxdepth 1 -name ".*"); do
|
|
[ "$file" = "$DOTFILES_DIR/.git" ] && continue
|
|
[ "$file" = "$DOTFILES_DIR/.github" ] && continue
|
|
[ "$file" = "$DOTFILES_DIR/.vscode" ] && continue
|
|
[ "$file" = "$DOTFILES_DIR/.config" ] && continue # Handle .config separately
|
|
basefile="$(basename "$file")"
|
|
if [ -f "$file" ] || [ -d "$file" ]; then
|
|
ln -sf "$file" "$HOME/$basefile"
|
|
echo "Linked $basefile"
|
|
fi
|
|
done
|
|
|
|
# Symlink .config directory contents
|
|
CONFIG_DIR="$DOTFILES_DIR/.config"
|
|
if [ -d "$CONFIG_DIR" ]; then
|
|
echo "Symlinking .config contents (files only, recursive)..."
|
|
find "$CONFIG_DIR" -type f | while read -r srcfile; do
|
|
# Get relative path from $CONFIG_DIR
|
|
relpath="${srcfile#$CONFIG_DIR/}"
|
|
targetfile="$HOME/.config/$relpath"
|
|
targetdir="$(dirname "$targetfile")"
|
|
# If targetdir is a symlink, remove it first
|
|
[ -L "$targetdir" ] && rm "$targetdir"
|
|
mkdir -p "$targetdir"
|
|
# Remove existing file/symlink at target
|
|
[ -L "$targetfile" ] && rm "$targetfile"
|
|
[ -f "$targetfile" ] && rm "$targetfile"
|
|
ln -sf "$srcfile" "$targetfile"
|
|
echo "Linked $srcfile -> $targetfile"
|
|
done
|
|
|
|
# =====================
|
|
# Device-specific symlinks for Hyprland and Waybar
|
|
# =====================
|
|
# This section handles device-specific config fragments for Hyprland, Waybar, etc.
|
|
# Uses $DOTFILES_DEVICE (set by setup.sh) and $HOSTNAME for profile-specific fragments.
|
|
# To add new device types (e.g., tablet, server), update host-profiles.conf and add fragments.
|
|
# To add new fragment types, extend the fragment_types array below.
|
|
# Format: "source_fragment_path:target_symlink_path"
|
|
# Example: fragment_types=(
|
|
# "hypr/includes/monitors-$HOSTNAME.conf:hypr/includes/monitors.conf"
|
|
# "hypr/includes/hypridle-$DOTFILES_DEVICE.conf:hypr/hypridle.conf"
|
|
# "waybar/config-$DOTFILES_DEVICE:waybar/config"
|
|
# )
|
|
|
|
if [ -z "$DOTFILES_DEVICE" ]; then
|
|
echo "ERROR: DOTFILES_DEVICE environment variable not set. Run setup.sh to detect device profile."
|
|
exit 1
|
|
fi
|
|
HOSTNAME=$(hostname)
|
|
|
|
# Device-specific fragments to symlink (source:target)
|
|
fragment_types=(
|
|
"hypr/includes/monitors-$HOSTNAME.conf:hypr/includes/monitors.conf" # Monitor layout per host
|
|
"hypr/includes/hypridle-$DOTFILES_DEVICE.conf:hypr/hypridle.conf" # Idle config per device type
|
|
"waybar/config-$DOTFILES_DEVICE:waybar/config" # Waybar config per device type
|
|
)
|
|
|
|
# Symlink each device-specific fragment
|
|
for fragment in "${fragment_types[@]}"; do
|
|
src="${CONFIG_DIR}/${fragment%%:*}"
|
|
tgt_rel="${fragment##*:}"
|
|
tgt="$HOME/.config/$tgt_rel"
|
|
tgt_dir="$(dirname "$tgt")"
|
|
mkdir -p "$tgt_dir"
|
|
if [ -f "$src" ]; then
|
|
# Remove existing file/symlink at target
|
|
[ -L "$tgt" ] && rm "$tgt"
|
|
[ -f "$tgt" ] && rm "$tgt"
|
|
ln -sf "$src" "$tgt"
|
|
echo "Linked $src -> $tgt"
|
|
else
|
|
echo "Warning: Device-specific fragment missing: $src"
|
|
# To troubleshoot, ensure the fragment exists for your device/host
|
|
fi
|
|
done
|
|
# =====================
|
|
# End device-specific symlinking
|
|
# =====================
|
|
|
|
fi
|
|
|
|
echo "====================="
|
|
echo "Dotfiles symlinking complete!"
|
|
echo "====================="
|
|
|
|
# Symlink .local/bin scripts
|
|
LOCAL_BIN_REPO="$DOTFILES_DIR/.local/bin"
|
|
LOCAL_BIN_HOME="$HOME/.local/bin"
|
|
if [ -d "$LOCAL_BIN_REPO" ]; then
|
|
mkdir -p "$LOCAL_BIN_HOME"
|
|
echo "Symlinking .local/bin scripts..."
|
|
for script in "$LOCAL_BIN_REPO"/*; do
|
|
[ -e "$script" ] || continue
|
|
base_script="$(basename "$script")"
|
|
ln -sf "$script" "$LOCAL_BIN_HOME/$base_script"
|
|
echo "Linked .local/bin/$base_script"
|
|
done
|
|
fi
|
|
|