dotfiles/modules/02-symlinks.sh
Martin Büchler f20f7179ef chore(hyprland): remove wl-clipboard-history and autostart usage; add network-manager-applet; ensure both JetBrains Mono font variants are installed
chore(setup): unify device profile detection and symlink logic via PROFILE env var

🤖 Generated with opencode.ai

Co-Authored-By: opencode <noreply@opencode.ai>
2025-08-08 11:54:58 +02:00

102 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# Ensure required directories exist
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..."
for item in "$CONFIG_DIR"/*; do
[ -e "$item" ] || continue
baseitem="$(basename "$item")"
target_dir="$HOME/.config/$baseitem"
# Remove existing symlink or directory to avoid conflicts
[ -L "$target_dir" ] && rm "$target_dir"
[ -d "$target_dir" ] && [ ! -L "$target_dir" ] && rm -rf "$target_dir"
ln -sf "$item" "$target_dir"
echo "Linked .config/$baseitem"
done
# Device-specific symlinks for Hyprland and Waybar using $PROFILE from setup.sh
if [ -z "$PROFILE" ]; then
echo "ERROR: PROFILE environment variable not set. Run setup.sh to detect profile."
exit 1
fi
HOSTNAME=$(hostname)
# Hyprland monitors
if [ -f "$CONFIG_DIR/hypr/includes/monitors-$HOSTNAME.conf" ]; then
ln -sf "$CONFIG_DIR/hypr/includes/monitors-$HOSTNAME.conf" "$CONFIG_DIR/hypr/includes/monitors.conf"
echo "Linked monitors-$HOSTNAME.conf as monitors.conf"
else
echo "Warning: No monitors config for hostname $HOSTNAME"
fi
# Hyprland hypridle
if [ -f "$CONFIG_DIR/hypr/includes/hypridle-$PROFILE.conf" ]; then
ln -sf "$CONFIG_DIR/hypr/includes/hypridle-$PROFILE.conf" "$CONFIG_DIR/hypr/hypridle.conf"
echo "Linked hypridle-$PROFILE.conf as hypridle.conf"
fi
# Waybar config
if [ -f "$CONFIG_DIR/waybar/config-$PROFILE" ]; then
ln -sf "$CONFIG_DIR/waybar/config-$PROFILE" "$CONFIG_DIR/waybar/config"
echo "Linked config-$PROFILE as waybar config"
fi
if [ -z "$PROFILE" ]; then
echo "ERROR: No profile mapping found for hostname '$HOSTNAME' in $DOTFILES_DIR/host-profiles.conf"
exit 1
fi
# Hyprland monitors
if [ -f "$CONFIG_DIR/hypr/includes/monitors-$HOSTNAME.conf" ]; then
ln -sf "$CONFIG_DIR/hypr/includes/monitors-$HOSTNAME.conf" "$CONFIG_DIR/hypr/includes/monitors.conf"
echo "Linked monitors-$HOSTNAME.conf as monitors.conf"
else
echo "Warning: No monitors config for hostname $HOSTNAME"
fi
# Hyprland hypridle
if [ -f "$CONFIG_DIR/hypr/includes/hypridle-$PROFILE.conf" ]; then
ln -sf "$CONFIG_DIR/hypr/includes/hypridle-$PROFILE.conf" "$CONFIG_DIR/hypr/hypridle.conf"
echo "Linked hypridle-$PROFILE.conf as hypridle.conf"
fi
# Waybar config
if [ -f "$CONFIG_DIR/waybar/config-$PROFILE" ]; then
ln -sf "$CONFIG_DIR/waybar/config-$PROFILE" "$CONFIG_DIR/waybar/config"
echo "Linked config-$PROFILE as waybar config"
fi
fi
echo "Dotfiles setup complete!"
# 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