Files
provision/config/link-dotfiles.sh
2026-01-22 20:54:36 -08:00

145 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/common.sh"
log_info "Linking configuration files"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
# Link bash configuration
log_info "Setting up bash configuration"
if ! grep -q "source $SCRIPT_DIR/bashrc" "$HOME/.bashrc" 2>/dev/null; then
echo "" >> "$HOME/.bashrc"
echo "# Added by provision" >> "$HOME/.bashrc"
echo "source $SCRIPT_DIR/bashrc" >> "$HOME/.bashrc"
log_success "Added bash configuration to ~/.bashrc"
else
log_info "Bash configuration already in ~/.bashrc"
fi
if [ -f "$HOME/.bash_profile" ]; then
if ! grep -q "source $SCRIPT_DIR/bashrc" "$HOME/.bash_profile" 2>/dev/null; then
echo "" >> "$HOME/.bash_profile"
echo "# Added by provision" >> "$HOME/.bash_profile"
echo "source $SCRIPT_DIR/bashrc" >> "$HOME/.bash_profile"
log_success "Added bash configuration to ~/.bash_profile"
else
log_info "Bash configuration already in ~/.bash_profile"
fi
fi
# Link tmux configuration
log_info "Setting up tmux configuration"
ensure_dir "$XDG_CONFIG_HOME/tmux"
safe_symlink "$SCRIPT_DIR/tmux.conf" "$XDG_CONFIG_HOME/tmux/tmux.conf"
# Link starship configuration
log_info "Setting up starship configuration"
safe_symlink "$SCRIPT_DIR/starship.toml" "$XDG_CONFIG_HOME/starship.toml"
# Link git configuration
log_info "Setting up git configuration"
if [ -f "$HOME/.gitconfig" ]; then
log_warn "~/.gitconfig already exists, skipping (edit $SCRIPT_DIR/gitconfig and copy manually)"
else
safe_symlink "$SCRIPT_DIR/gitconfig" "$HOME/.gitconfig"
log_warn "Remember to edit ~/.gitconfig and set your name and email!"
fi
safe_symlink "$SCRIPT_DIR/gitignore_global" "$HOME/.gitignore_global"
# Link X11 configuration (Linux only)
if is_linux; then
log_info "Setting up X11 configuration"
if [ -f "$SCRIPT_DIR/xinitrc" ]; then
safe_symlink "$SCRIPT_DIR/xinitrc" "$HOME/.xinitrc"
chmod +x "$HOME/.xinitrc"
fi
if [ -f "$SCRIPT_DIR/xsession" ]; then
safe_symlink "$SCRIPT_DIR/xsession" "$HOME/.xsession"
chmod +x "$HOME/.xsession"
fi
if [ -f "$SCRIPT_DIR/Xresources" ]; then
safe_symlink "$SCRIPT_DIR/Xresources" "$HOME/.Xresources"
fi
if [ -f "$SCRIPT_DIR/twm/twmrc" ]; then
safe_symlink "$SCRIPT_DIR/twm/twmrc" "$HOME/.twmrc"
fi
# Install XDM customizations (requires sudo)
if [ -d "$SCRIPT_DIR/xdm" ]; then
log_info "Installing XDM customizations"
# Determine XDM config directory based on distro
if [ -d "/etc/X11/xdm" ]; then
XDM_DIR="/etc/X11/xdm"
elif [ -d "/etc/xdm" ]; then
XDM_DIR="/etc/xdm"
else
log_warn "XDM config directory not found, skipping XDM customization"
XDM_DIR=""
fi
if [ -n "$XDM_DIR" ]; then
# Backup existing files
for file in Xresources Xsetup Xstartup; do
if [ -f "$XDM_DIR/$file" ]; then
maybe_sudo cp "$XDM_DIR/$file" "$XDM_DIR/$file.backup" 2>/dev/null || true
fi
done
# Install custom files
maybe_sudo cp "$SCRIPT_DIR/xdm/Xresources" "$XDM_DIR/Xresources"
maybe_sudo cp "$SCRIPT_DIR/xdm/Xsetup" "$XDM_DIR/Xsetup"
maybe_sudo cp "$SCRIPT_DIR/xdm/Xstartup" "$XDM_DIR/Xstartup"
# Make scripts executable
maybe_sudo chmod +x "$XDM_DIR/Xsetup"
maybe_sudo chmod +x "$XDM_DIR/Xstartup"
log_success "XDM customizations installed to $XDM_DIR"
fi
fi
fi
# Install VSCode extensions
if command_exists codium || command_exists code; then
if [ -f "$SCRIPT_DIR/vscode-extensions.txt" ]; then
log_info "Installing VSCode/VSCodium extensions"
CODE_CMD="codium"
if ! command_exists codium && command_exists code; then
CODE_CMD="code"
fi
while IFS= read -r extension; do
# Skip empty lines and comments
[[ -z "$extension" || "$extension" =~ ^[[:space:]]*# ]] && continue
if $CODE_CMD --list-extensions 2>/dev/null | grep -qi "^$extension$"; then
log_info "Extension already installed: $extension"
else
log_info "Installing extension: $extension"
$CODE_CMD --install-extension "$extension" --force 2>/dev/null || log_warn "Failed to install: $extension"
fi
done < "$SCRIPT_DIR/vscode-extensions.txt"
fi
else
log_info "VSCode/VSCodium not installed, skipping extensions"
fi
log_success "Configuration files linked successfully"
log_info ""
log_info "Next steps:"
log_info " 1. Edit ~/.gitconfig to set your name and email"
log_info " 2. Restart your shell: exec \$SHELL"
log_info " 3. Install tmux plugins: press Ctrl+a then I in tmux"
if is_linux; then
log_info " 4. Enable XDM (optional): sudo systemctl enable xdm && sudo systemctl start xdm"
fi