mirror of
https://github.com/andwati/dotfiles.git
synced 2026-11-16 16:55:13 +00:00
83 lines
3.1 KiB
Bash
Executable File
83 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Bootstraps dotfiles on a new machine: installs oh-my-zsh + the custom
|
|
# theme/plugins .zshrc expects, then symlinks packages into $HOME via
|
|
# GNU Stow (each top-level dir is a package mirroring $HOME, e.g.
|
|
# zsh/.zshrc -> ~/.zshrc). Add a new package by adding a new top-level dir.
|
|
set -euo pipefail
|
|
|
|
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
|
|
|
|
# Arch packages the dotfiles rely on; yay only runs if something is missing.
|
|
pkgs=(
|
|
stow git curl zsh gnupg pinentry
|
|
neovim ripgrep fd fzf zoxide eza wl-clipboard gcc make jdk21-openjdk
|
|
)
|
|
mapfile -t missing < <(pacman -T "${pkgs[@]}" || true)
|
|
if [ "${#missing[@]}" -gt 0 ]; then
|
|
yay -S --needed "${missing[@]}"
|
|
fi
|
|
|
|
clone_if_missing() {
|
|
local url="$1" dst="$2"
|
|
[ -d "$dst" ] || git clone --depth=1 "$url" "$dst"
|
|
}
|
|
|
|
if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
|
echo "Installing oh-my-zsh..."
|
|
RUNZSH=no CHSH=no KEEP_ZSHRC=yes sh -c \
|
|
"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
|
fi
|
|
|
|
clone_if_missing https://github.com/romkatv/powerlevel10k.git "$ZSH_CUSTOM/themes/powerlevel10k"
|
|
clone_if_missing https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions"
|
|
clone_if_missing https://github.com/zsh-users/zsh-syntax-highlighting.git "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
|
|
clone_if_missing https://github.com/zsh-users/zsh-history-substring-search "$ZSH_CUSTOM/plugins/zsh-history-substring-search"
|
|
clone_if_missing https://github.com/zsh-users/zsh-completions "$ZSH_CUSTOM/plugins/zsh-completions"
|
|
clone_if_missing https://github.com/MichaelAquilina/zsh-you-should-use "$ZSH_CUSTOM/plugins/you-should-use"
|
|
clone_if_missing https://github.com/MichaelAquilina/zsh-autoswitch-virtualenv "$ZSH_CUSTOM/plugins/autoswitch_virtualenv"
|
|
|
|
# Stow refuses to link over a real (non-symlink) file, so move any
|
|
# conflicting pre-existing file aside first (e.g. the .zshrc oh-my-zsh's
|
|
# own installer just wrote above).
|
|
stow_package() {
|
|
local pkg="$1" f rel target
|
|
while IFS= read -r -d '' f; do
|
|
rel="${f#"$DOTFILES_DIR/$pkg/"}"
|
|
target="$HOME/$rel"
|
|
case "$(realpath -m "$target")" in
|
|
"$DOTFILES_DIR"/*) continue ;;
|
|
esac
|
|
if [ -L "$target" ]; then
|
|
rm "$target"
|
|
elif [ -e "$target" ]; then
|
|
mkdir -p "$(dirname "$target")"
|
|
mv "$target" "$target.bak.$(date +%s)"
|
|
echo "Backed up existing $target"
|
|
fi
|
|
done < <(find "$DOTFILES_DIR/$pkg" -type f -print0)
|
|
stow --dir="$DOTFILES_DIR" --target="$HOME" --restow "$pkg"
|
|
echo "Stowed $pkg"
|
|
}
|
|
|
|
mkdir -p "$HOME/.gnupg" && chmod 700 "$HOME/.gnupg"
|
|
|
|
stow_package zsh
|
|
stow_package gnupg
|
|
stow_package git
|
|
stow_package ghostty
|
|
stow_package kde
|
|
stow_package nvim
|
|
stow_package vscode
|
|
gpgconf --kill gpg-agent 2>/dev/null || true
|
|
|
|
cat <<'EOF'
|
|
|
|
Done. This does NOT install (grab these separately if missing):
|
|
- pyenv, pnpm, deno, rustup, docker
|
|
- ghostty, lazygit, tree-sitter-cli, VS Code (AUR)
|
|
- a Nerd Font (JetBrains Mono Nerd Font) — set it as your terminal's font
|
|
|
|
Start a new shell to pick everything up: exec zsh
|
|
EOF
|