dotfiles/install.sh
2026-07-03 09:41:20 +02:00

119 lines
3.2 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DRY_RUN=false
for arg in "$@"; do
[[ "$arg" == "--dry-run" ]] && DRY_RUN=true
done
$DRY_RUN && echo "[DRY RUN] No changes will be made."
run() {
if $DRY_RUN; then
echo "[DRY RUN] Would run: $*"
else
"$@"
fi
}
step() { echo "==> $*"; }
# ---------------------------------------------------------------------------
# 1. Homebrew
# ---------------------------------------------------------------------------
step "Checking Homebrew"
if ! command -v brew &>/dev/null; then
if $DRY_RUN; then
echo "[DRY RUN] Would install Homebrew"
else
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi
# ---------------------------------------------------------------------------
# 2. Install packages
# ---------------------------------------------------------------------------
step "Installing packages from Brewfile"
run brew bundle install --file="$DOTFILES_DIR/Brewfile" --no-lock
# ---------------------------------------------------------------------------
# 3. Set fish as default shell
# ---------------------------------------------------------------------------
step "Setting fish as default shell"
FISH_PATH="$(command -v fish || true)"
if [[ -z "$FISH_PATH" ]]; then
echo "ERROR: fish not found after brew install — cannot set as default shell"
exit 1
fi
if [[ "$SHELL" != "$FISH_PATH" ]]; then
if ! grep -qF "$FISH_PATH" /etc/shells; then
echo "Adding $FISH_PATH to /etc/shells (requires sudo)"
run sudo sh -c "echo '$FISH_PATH' >> /etc/shells"
fi
run chsh -s "$FISH_PATH"
else
echo "fish is already the default shell"
fi
# ---------------------------------------------------------------------------
# 4. Copy configs
# ---------------------------------------------------------------------------
CONFIGS=(
"fish"
"starship.toml"
"nvim"
"git"
"herdr"
"tmux"
"aerospace"
"ghostty"
)
step "Copying configs to ~/.config/"
for name in "${CONFIGS[@]}"; do
src="$DOTFILES_DIR/.config/$name"
dst="$HOME/.config/$name"
if [[ ! -e "$src" ]]; then
echo " skip: $src not found in repo"
continue
fi
if [[ -e "$dst" ]]; then
if $DRY_RUN; then
echo "[DRY RUN] Would backup $dst → ${dst}.bak"
echo "[DRY RUN] Would copy $src → $dst"
else
echo " backup: $dst → ${dst}.bak"
rm -rf "${dst}.bak"
cp -r "$dst" "${dst}.bak"
rm -rf "$dst"
cp -r "$src" "$dst"
fi
else
if $DRY_RUN; then
echo "[DRY RUN] Would copy $src → $dst"
else
echo " copy: $src → $dst"
cp -r "$src" "$dst"
fi
fi
done
# ---------------------------------------------------------------------------
# 5. tmux plugin manager (tpm)
# ---------------------------------------------------------------------------
step "Setting up tpm (tmux plugin manager)"
TPM_DIR="$HOME/.config/tmux/plugins/tpm"
if [[ ! -d "$TPM_DIR" ]]; then
run git clone https://github.com/tmux-plugins/tpm "$TPM_DIR"
else
echo "tpm already installed"
fi
echo ""
echo "Done. Open a new terminal to start using fish."
$DRY_RUN && echo "(This was a dry run — no changes were made.)"