From 0056269e68a3e3fa1bd317c365a6d77b89fa8711 Mon Sep 17 00:00:00 2001 From: conuko <50672977+conuko@users.noreply.github.com> Date: Mon, 2 Nov 2026 20:41:29 +0100 Subject: [PATCH 1/2] feat: modernize dotfiles with mise, starship and XDG git config - Replace oh-my-zsh, powerlevel10k, nvm, pyenv, rbenv and pipx with plain zsh, Homebrew plugins, Starship and mise (reads .nvmrc/.python-version/.ruby-version) - Cache tool init scripts; shell startup drops from ~4s to ~160ms - Move shared git config to ~/.config/git so `git config --global` writes to the untracked ~/.gitconfig; add current git defaults, delta and SSH signing - Add fzf, zoxide, eza, bat, fd, git-lfs, uv, shellcheck and the Ghostty config - Manage ~/.zprofile, keep dotfiles/bin off PATH, back up with relative paths - Add a lint workflow and rewrite the README Co-Authored-By: Claude Opus 5.5 --- .github/workflows/lint.yml | 26 ++++++++ .gitignore | 1 + Brewfile | 39 +++++++---- README.md | 120 +++++++++++++++++++--------------- bin/bootstrap | 41 +++++++++++- bin/link | 53 ++++++++++----- bin/update | 19 ++++++ ghostty/config.ghostty | 8 +++ git/gitconfig | 99 ++++++++++++++++------------ git/gitignore | 3 +- local/gitconfig.example | 8 +++ local/gitconfig.local.example | 7 -- local/zshrc.local.example | 4 +- macos/defaults.sh | 7 ++ mise/config.toml | 15 +++++ starship/starship.toml | 72 ++++++++++++++++++++ zsh/aliases.zsh | 12 ++++ zsh/completion.zsh | 30 +++++++++ zsh/exports.zsh | 8 +-- zsh/options.zsh | 34 ++++++++++ zsh/path.zsh | 23 ++++--- zsh/plugins.zsh | 27 ++------ zsh/tools.zsh | 43 ++++++++++++ zsh/zprofile | 9 +++ zsh/zshrc | 13 ++-- 25 files changed, 545 insertions(+), 176 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 ghostty/config.ghostty create mode 100644 local/gitconfig.example delete mode 100644 local/gitconfig.local.example create mode 100644 mise/config.toml create mode 100644 starship/starship.toml create mode 100644 zsh/completion.zsh create mode 100644 zsh/options.zsh create mode 100644 zsh/tools.zsh create mode 100644 zsh/zprofile diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..ec5610a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,26 @@ +name: Lint + +on: + push: + pull_request: + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - name: Install zsh + run: sudo apt-get update && sudo apt-get install -y zsh + + - name: ShellCheck + run: shellcheck bin/bootstrap bin/link bin/macos bin/update macos/defaults.sh + + - name: zsh syntax + run: for f in zsh/zshrc zsh/zprofile zsh/*.zsh; do zsh -n "$f"; done + + - name: Python syntax + run: python3 -m py_compile bin/optional/fetch-gitlab-mr-review-comments diff --git a/.gitignore b/.gitignore index 51ca7a5..0792f11 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.swo *~ Brewfile.local +__pycache__/ diff --git a/Brewfile b/Brewfile index fb8d02c..db436d6 100644 --- a/Brewfile +++ b/Brewfile @@ -1,20 +1,33 @@ -tap "oven-sh/bun" - +# Git brew "git" +brew "git-lfs" +brew "git-delta" brew "gh" -brew "gnupg" -brew "diff-so-fancy" -brew "neovim" +brew "glab" +brew "lazygit" + +# Shell +brew "starship" +brew "zsh-autosuggestions" +brew "zsh-syntax-highlighting" +brew "zsh-completions" +brew "fzf" +brew "zoxide" +brew "eza" +brew "bat" +brew "fd" brew "ripgrep" brew "jq" -brew "lazygit" -brew "node" -brew "pnpm" -brew "oven-sh/bun/bun" -brew "pyenv" -brew "rbenv" -brew "pipx" -brew "go" + +# Development (language runtimes are managed by mise, see mise/config.toml) +brew "mise" +brew "uv" +brew "neovim" +brew "shellcheck" + +# Media and web brew "ffmpeg" brew "svgo" brew "mkcert" + +cask "ghostty" diff --git a/README.md b/README.md index 3e15771..f409509 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,11 @@ My personal and opinionated macOS dotfiles, adapted from the general structure a ## What's managed -- `zsh` configuration with `oh-my-zsh`, `powerlevel10k`, `nvm`, `pyenv`, `rbenv`, `pnpm`, `pipx`, and GitHub Copilot shell aliases -- Git config and global gitignore -- Homebrew package bootstrap via `Brewfile` +- `zsh` configuration without a framework: Homebrew plugins (autosuggestions, syntax highlighting, completions), a [Starship](https://starship.rs) prompt, [fzf](https://github.com/junegunn/fzf), [zoxide](https://github.com/ajeetdsouza/zoxide), and `eza`/`bat`/`fd` aliases +- Language runtimes with [mise](https://mise.jdx.dev) (Node, pnpm, Bun, Python, Go, Yarn, Poetry), including automatic switching from `.nvmrc`, `.node-version`, `.python-version` and `.ruby-version` +- Git config with current defaults, [delta](https://github.com/dandavison/delta) for diffs, and SSH commit signing +- [Ghostty](https://ghostty.org) terminal config +- Homebrew packages via `Brewfile` - Safe macOS defaults ## What's not managed @@ -21,19 +23,24 @@ My personal and opinionated macOS dotfiles, adapted from the general structure a ```text dotfiles/ ├── Brewfile -├── bin/ -│ └── optional/ -├── git/ -├── local/ +├── bin/ bootstrap, link, update, macos +│ └── optional/ opt-in helper scripts +├── ghostty/ → ~/.config/ghostty/config.ghostty +├── git/ → ~/.config/git/config, ~/.config/git/ignore +├── local/ templates for untracked machine-local files ├── macos/ -└── zsh/ +├── mise/ → ~/.config/mise/config.toml +├── starship/ → ~/.config/starship.toml +└── zsh/ → ~/.zshrc, ~/.zprofile ``` ## Commands +The scripts are not on `PATH`; call them by path. + ### Bootstrap a machine -Runs Homebrew setup, installs the tracked packages, creates missing local override files, links managed dotfiles, and optionally applies macOS defaults. +Installs Homebrew and the tracked packages, links managed dotfiles, creates missing local files, installs mise runtimes, and optionally applies macOS defaults. ```bash ~/dotfiles/bin/bootstrap @@ -42,7 +49,7 @@ Runs Homebrew setup, installs the tracked packages, creates missing local overri ### Relink managed dotfiles -Safely backs up conflicting existing files in `~/.dotfiles-backups//`. +Safely backs up conflicting existing files in `~/.dotfiles-backups//`, keeping their path relative to `~`. Running it again changes nothing. ```bash ~/dotfiles/bin/link @@ -54,14 +61,58 @@ Safely backs up conflicting existing files in `~/.dotfiles-backups//` ~/dotfiles/bin/macos ``` -### Update the repo and re-apply config +### Update everything -If the repository has an `origin` remote, this pulls with `--ff-only` before refreshing packages and links. +Pulls the repo (`--ff-only`), upgrades Homebrew packages and mise runtimes, upgrades `gh` extensions, relinks, and lists installed packages that no Brewfile mentions. ```bash ~/dotfiles/bin/update ``` +## Managed home files + +| Home file | Repo file | +| --- | --- | +| `~/.zshrc` | `zsh/zshrc` | +| `~/.zprofile` | `zsh/zprofile` | +| `~/.config/git/config` | `git/gitconfig` | +| `~/.config/git/ignore` | `git/gitignore` | +| `~/.config/mise/config.toml` | `mise/config.toml` | +| `~/.config/starship.toml` | `starship/starship.toml` | +| `~/.config/ghostty/config.ghostty` | `ghostty/config.ghostty` | + +## Local overrides + +These files are intentionally outside the repo and are safe for machine-specific or private values: + +- `~/.gitconfig`: identity, signing key, and anything `git config --global` writes. Git reads it after `~/.config/git/config`, so its values win. +- `~/.zshrc.local`: sourced at the end of `~/.zshrc` +- `~/.config/git/allowed_signers`: lets git verify your own SSH signatures +- `~/dotfiles/Brewfile.local`: extra packages for this machine (git-ignored) + +Bootstrap creates the first two from `local/gitconfig.example` and `local/zshrc.local.example` when missing, and generates `allowed_signers` from `user.email` and `~/.ssh/id_ed25519.pub`. + +## Commit signing + +Commits and tags are signed with SSH (`gpg.format = ssh`). On a new machine: + +1. Set `user.name`, `user.email` and `user.signingkey = ~/.ssh/id_ed25519.pub` in `~/.gitconfig`. +2. Run `~/dotfiles/bin/bootstrap` (or create `~/.config/git/allowed_signers` yourself). +3. Add the public key as a **signing** key on GitHub (`gh ssh-key add ~/.ssh/id_ed25519.pub --type signing`) and on GitLab (key usage "Authentication & Signing"). + +## Runtimes with mise + +Global versions live in `mise/config.toml`. In a project, mise reads `mise.toml` or the version files of other managers (`.nvmrc` and friends) and switches versions when you `cd` into it, so there is no `nvm use` step. + +```bash +mise install # install everything the current directory needs +mise use node@22 # pin a version for the current project (writes mise.toml) +mise ls # show installed and active versions +mise doctor # check the setup +``` + +Interactive shells use `mise activate`. Login shells started by GUI apps and editors get the mise shims through `~/.zprofile`. + ## Optional scripts Scripts in `bin/optional/` are **not** on `PATH` by default. To opt in, add this to `~/.zshrc.local`: @@ -92,47 +143,12 @@ fetch-gitlab-mr-review-comments https://gitlab.example.com/group/project/-/merge Requires `glab` on `PATH` with access to the GitLab project. -## Managed home files - -- `~/.zshrc` -> `~/dotfiles/zsh/zshrc` -- `~/.gitconfig` -> `~/dotfiles/git/gitconfig` -- `~/.gitignore` -> `~/dotfiles/git/gitignore` - -## Local overrides - -These files are intentionally outside the repo and are safe for machine-specific or private values: - -- `~/.gitconfig.local` -- `~/.zshrc.local` +## Brewfile scope -Bootstrap creates them from these templates when missing: +The tracked `Brewfile` contains the core daily tools, grouped by purpose: Git (`git`, `git-lfs`, `git-delta`, `gh`, `glab`, `lazygit`), shell (`starship`, zsh plugins, `fzf`, `zoxide`, `eza`, `bat`, `fd`, `ripgrep`, `jq`), development (`mise`, `uv`, `neovim`, `shellcheck`), media and web (`ffmpeg`, `svgo`, `mkcert`), and the Ghostty cask. Language runtimes come from mise, not Homebrew. -- `~/dotfiles/local/gitconfig.local.example` -- `~/dotfiles/local/zshrc.local.example` +Put extra machine-local packages in the untracked `Brewfile.local`; `bin/bootstrap` and `bin/update` load it when it exists. -## Brewfile scope +## CI -The tracked `Brewfile` contains the core daily tools for my machine: - -- `git` -- `gh` -- `gnupg` -- `diff-so-fancy` -- `neovim` -- `ripgrep` -- `jq` -- `lazygit` -- `node` -- `pnpm` -- `bun` -- `pyenv` -- `rbenv` -- `pipx` -- `go` -- `ffmpeg` -- `svgo` -- `mkcert` - -If you want extra machine-local packages later, add them to a non-tracked `Brewfile.local` and keep the tracked file curated. - -`bin/bootstrap` and `bin/update` also load `~/dotfiles/Brewfile.local` when it exists. +`.github/workflows/lint.yml` runs ShellCheck on the scripts and syntax-checks the zsh and Python files on every push. diff --git a/bin/bootstrap b/bin/bootstrap index 678d81b..b6a6faf 100755 --- a/bin/bootstrap +++ b/bin/bootstrap @@ -3,6 +3,7 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" RUN_MACOS=0 for arg in "$@"; do @@ -25,6 +26,15 @@ ensure_homebrew() { echo "Installing Homebrew..." NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + # A fresh install is not on PATH yet in this process. + local brew_bin + for brew_bin in /opt/homebrew/bin/brew /usr/local/bin/brew; do + if [[ -x "$brew_bin" ]]; then + eval "$("$brew_bin" shellenv)" + return 0 + fi + done } copy_if_missing() { @@ -48,6 +58,27 @@ install_brewfile_if_present() { fi } +# Git verifies SSH commit signatures against this file. It holds your email, so it stays untracked. +ensure_allowed_signers() { + local signers="$CONFIG_HOME/git/allowed_signers" + local key="$HOME/.ssh/id_ed25519.pub" + local email + + if [[ -e "$signers" ]]; then + echo "Unchanged: $signers" + return 0 + fi + + email="$(git config --global user.email || true)" + if [[ ! -f "$key" || -z "$email" || "$email" == "you@example.com" ]]; then + echo "Skipped: $signers (set user.email in ~/.gitconfig and create $key first)" + return 0 + fi + + printf '%s namespaces="git" %s\n' "$email" "$(cut -d' ' -f1,2 "$key")" > "$signers" + echo "Created: $signers" +} + ensure_homebrew if command -v brew >/dev/null 2>&1; then @@ -55,10 +86,16 @@ if command -v brew >/dev/null 2>&1; then install_brewfile_if_present "$ROOT/Brewfile.local" fi -copy_if_missing "$ROOT/local/gitconfig.local.example" "$HOME/.gitconfig.local" +# Linking runs first because it migrates an old ~/.gitconfig symlink out of the way. +"$ROOT/bin/link" + +copy_if_missing "$ROOT/local/gitconfig.example" "$HOME/.gitconfig" copy_if_missing "$ROOT/local/zshrc.local.example" "$HOME/.zshrc.local" +ensure_allowed_signers -"$ROOT/bin/link" +if command -v mise >/dev/null 2>&1; then + mise install +fi if [[ $RUN_MACOS -eq 1 ]]; then "$ROOT/bin/macos" diff --git a/bin/link b/bin/link index dc9c419..896ec76 100755 --- a/bin/link +++ b/bin/link @@ -3,32 +3,24 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" TIMESTAMP="$(date +%Y%m%d-%H%M%S)" BACKUP_DIR="$HOME/.dotfiles-backups/$TIMESTAMP" -BACKUP_CREATED=0 backup_target() { local target="$1" - local backup_name + local backup_path="$BACKUP_DIR/${target#"$HOME"/}" - backup_name="$(basename "$target")" - - if [[ $BACKUP_CREATED -eq 0 ]]; then - mkdir -p "$BACKUP_DIR" - BACKUP_CREATED=1 - fi - - mv "$target" "$BACKUP_DIR/$backup_name" - echo "Backed up $target -> $BACKUP_DIR/$backup_name" + mkdir -p "$(dirname "$backup_path")" + mv "$target" "$backup_path" + echo "Backed up $target -> $backup_path" } link_file() { local source="$1" local target="$2" - local target_dir - target_dir="$(dirname "$target")" - mkdir -p "$target_dir" + mkdir -p "$(dirname "$target")" if [[ -L "$target" ]]; then if [[ "$(readlink "$target")" == "$source" ]]; then @@ -45,8 +37,37 @@ link_file() { echo "Linked: $target -> $source" } +# Earlier versions linked ~/.gitconfig and ~/.gitignore into the repo, which made +# `git config --global` write into tracked files. ~/.gitconfig is now a local file. +migrate_legacy() { + local legacy + + for legacy in "$HOME/.gitconfig" "$HOME/.gitignore"; do + if [[ -L "$legacy" && "$(readlink "$legacy")" == "$ROOT/"* ]]; then + backup_target "$legacy" + fi + done + + if [[ -f "$HOME/.gitconfig.local" && ! -e "$HOME/.gitconfig" ]]; then + mv "$HOME/.gitconfig.local" "$HOME/.gitconfig" + echo "Moved: ~/.gitconfig.local -> ~/.gitconfig" + fi + + # Ghostty also reads this file, and it would override the linked config. + local ghostty_legacy="$HOME/Library/Application Support/com.mitchellh.ghostty/config.ghostty" + if [[ -f "$ghostty_legacy" && ! -L "$ghostty_legacy" ]]; then + backup_target "$ghostty_legacy" + fi +} + +migrate_legacy + link_file "$ROOT/zsh/zshrc" "$HOME/.zshrc" -link_file "$ROOT/git/gitconfig" "$HOME/.gitconfig" -link_file "$ROOT/git/gitignore" "$HOME/.gitignore" +link_file "$ROOT/zsh/zprofile" "$HOME/.zprofile" +link_file "$ROOT/git/gitconfig" "$CONFIG_HOME/git/config" +link_file "$ROOT/git/gitignore" "$CONFIG_HOME/git/ignore" +link_file "$ROOT/mise/config.toml" "$CONFIG_HOME/mise/config.toml" +link_file "$ROOT/starship/starship.toml" "$CONFIG_HOME/starship.toml" +link_file "$ROOT/ghostty/config.ghostty" "$CONFIG_HOME/ghostty/config.ghostty" echo "Dotfile linking complete." diff --git a/bin/update b/bin/update index 5287827..93f2cf8 100755 --- a/bin/update +++ b/bin/update @@ -19,10 +19,29 @@ else fi if command -v brew >/dev/null 2>&1; then + brew update + brew upgrade install_brewfile_if_present "$ROOT/Brewfile" install_brewfile_if_present "$ROOT/Brewfile.local" fi "$ROOT/bin/link" +if command -v mise >/dev/null 2>&1; then + mise upgrade +fi + +if command -v gh >/dev/null 2>&1; then + gh extension upgrade --all || true +fi + +if command -v brew >/dev/null 2>&1; then + brew cleanup + + echo "Installed but not listed in a Brewfile (add them or uninstall them):" + cat "$ROOT/Brewfile" "$ROOT"/Brewfile.local 2>/dev/null | + brew bundle cleanup --file=- 2>/dev/null | + awk '/^Would remove|^Run `brew/ { exit } { print }' || true +fi + echo "Update complete." diff --git a/ghostty/config.ghostty b/ghostty/config.ghostty new file mode 100644 index 0000000..b0889f4 --- /dev/null +++ b/ghostty/config.ghostty @@ -0,0 +1,8 @@ +# Linked to ~/.config/ghostty/config.ghostty by bin/link. + +theme = dark:Apple System Colors, light:Apple System Colors Light +font-family = JetBrains Mono +font-size = 14 + +# Use the left Option key as Alt, so shell shortcuts such as Alt-C (fzf) work. +macos-option-as-alt = left diff --git a/git/gitconfig b/git/gitconfig index 9e2c222..e80f8f6 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -1,8 +1,10 @@ -[include] - path = ~/.gitconfig.local +# Shared defaults, linked to ~/.config/git/config. +# Identity, signing key and machine-specific settings live in the untracked +# ~/.gitconfig, which git reads after this file and `git config --global` writes to. [alias] co = checkout + sw = switch st = status hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short l = log --pretty=oneline -n 20 --graph --abbrev-commit @@ -12,7 +14,7 @@ p = pull --recurse-submodules c = clone --recursive ca = !git add -A && git commit -av - go = "!f() { git checkout -b \"$1\" 2> /dev/null || git checkout \"$1\"; }; f" + go = "!f() { git switch -c \"$1\" 2> /dev/null || git switch \"$1\"; }; f" tags = tag -l branches = branch --all remotes = remote --verbose @@ -29,60 +31,78 @@ contributors = shortlog --summary --numbered whoami = "!git config user.email && git config user.name && git config user.signingkey" latest-tag = "!git rev-list --tags --max-count=1 | git describe" - lt = "!git rev-list --tags --max-count=1 | git describe" - -[color] - branch = auto - diff = auto - status = auto - ui = true - -[color "branch"] - current = yellow reverse - local = yellow - remote = green - -[color "diff"] - meta = yellow bold - frag = magenta bold - old = red - new = cyan - -[color "status"] - added = green - changed = yellow - untracked = cyan - -[branch] - sort = -committerdate [core] - excludesfile = ~/.gitignore whitespace = space-before-tab,-indent-with-non-tab,trailing-space trustctime = false - precomposeunicode = false untrackedCache = true - pager = diff-so-fancy | less --tabs=4 -RFX + fsmonitor = true + pager = delta + +[interactive] + diffFilter = delta --color-only + +[delta] + navigate = true + +[column] + ui = auto + +[branch] + sort = -committerdate + +[tag] + sort = version:refname + gpgSign = true + +[init] + defaultBranch = main [commit] - gpgsign = true + gpgSign = true + verbose = true + +[gpg] + format = ssh + +[gpg "ssh"] + allowedSignersFile = ~/.config/git/allowed_signers [diff] + algorithm = histogram + colorMoved = plain + mnemonicPrefix = true renames = copies -[diff "bin"] - textconv = hexdump -v -C +[merge] + conflictStyle = zdiff3 + log = true + +[rerere] + enabled = true + autoUpdate = true [apply] whitespace = fix -[merge] - log = true +[fetch] + prune = true + pruneTags = true + all = true + +[pull] + rebase = true [push] default = simple + autoSetupRemote = true followTags = true +[rebase] + autoSquash = true + autoStash = true + updateRefs = true + [mergetool] keepBackup = false @@ -90,7 +110,4 @@ prompt = false [help] - autocorrect = 1 - -[init] - defaultBranch = main + autocorrect = prompt diff --git a/git/gitignore b/git/gitignore index 72debdc..1af021e 100644 --- a/git/gitignore +++ b/git/gitignore @@ -5,4 +5,5 @@ *.tmp *.bak .idea/ -.vscode/ + +**/.claude/settings.local.json diff --git a/local/gitconfig.example b/local/gitconfig.example new file mode 100644 index 0000000..77bb8d0 --- /dev/null +++ b/local/gitconfig.example @@ -0,0 +1,8 @@ +# Machine-local git settings: ~/.gitconfig (untracked). +# Git reads this after ~/.config/git/config, so values here win, +# and `git config --global` writes here instead of into the dotfiles repo. + +[user] + name = Your Name + email = you@example.com + signingkey = ~/.ssh/id_ed25519.pub diff --git a/local/gitconfig.local.example b/local/gitconfig.local.example deleted file mode 100644 index 77b5a8a..0000000 --- a/local/gitconfig.local.example +++ /dev/null @@ -1,7 +0,0 @@ -[user] - name = Your Name - email = you@example.com - signingkey = YOUR_SIGNING_KEY_ID - -[commit] - gpgsign = true diff --git a/local/zshrc.local.example b/local/zshrc.local.example index deab2f4..bc648b8 100644 --- a/local/zshrc.local.example +++ b/local/zshrc.local.example @@ -2,10 +2,10 @@ # This file is sourced from ~/.zshrc if present. # Example aliases: -# alias dotfiles="cd ~/dotfiles" +# alias work="cd ~/Projects" # Example local exports: -# export HOMEBREW_NO_ANALYTICS=1 +# export AWS_PROFILE=default # Add optional dotfiles scripts to PATH: # export PATH="$DOTFILES_DIR/bin/optional:$PATH" diff --git a/macos/defaults.sh b/macos/defaults.sh index f15341a..e0f7e4d 100755 --- a/macos/defaults.sh +++ b/macos/defaults.sh @@ -17,12 +17,19 @@ defaults write com.apple.finder AppleShowAllFiles -bool true defaults write com.apple.finder ShowPathbar -bool true defaults write com.apple.finder ShowStatusBar -bool true defaults write com.apple.finder FXPreferredViewStyle -string "Nlsv" +defaults write com.apple.finder _FXSortFoldersFirst -bool true +defaults write com.apple.finder FXDefaultSearchScope -string "SCcf" + +defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true +defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true defaults write com.apple.screencapture location -string "$SCREENSHOT_DIR" defaults write com.apple.screencapture type -string "png" +defaults write com.apple.screencapture disable-shadow -bool true defaults write NSGlobalDomain KeyRepeat -int 2 defaults write NSGlobalDomain InitialKeyRepeat -int 15 +defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode2 -bool true diff --git a/mise/config.toml b/mise/config.toml new file mode 100644 index 0000000..0cf4437 --- /dev/null +++ b/mise/config.toml @@ -0,0 +1,15 @@ +# Global runtimes, linked to ~/.config/mise/config.toml. +# Projects override these with mise.toml, .nvmrc, .node-version, .python-version or .ruby-version. + +[tools] +node = "lts" +pnpm = "latest" +bun = "latest" +python = "3.14" +go = "latest" +"npm:yarn" = "1" +"pipx:poetry" = "latest" + +[settings] +# Read version files from other version managers (off by default since mise 2025.10). +idiomatic_version_file_enable_tools = ["node", "python", "ruby"] diff --git a/starship/starship.toml b/starship/starship.toml new file mode 100644 index 0000000..dda2cc8 --- /dev/null +++ b/starship/starship.toml @@ -0,0 +1,72 @@ +"$schema" = "https://starship.rs/config-schema.json" + +# Lean single-line prompt. Only the modules listed in `format` are shown, +# so cloud context (gcloud, aws) and package versions stay out of the way. +add_newline = false +command_timeout = 500 + +format = """ +$hostname\ +$directory\ +$git_branch\ +$git_state\ +$git_status\ +$nodejs\ +$bun\ +$deno\ +$python\ +$golang\ +$ruby\ +$cmd_duration\ +$jobs\ +$character""" + +[hostname] +ssh_only = true +format = "[$hostname]($style) " + +[directory] +style = "bold blue" +truncation_length = 4 + +[git_branch] +format = "[$symbol$branch(:$remote_branch)]($style) " +style = "green" + +[git_state] +format = "[$state( $progress_current/$progress_total)]($style) " + +[git_status] +format = "([$all_status$ahead_behind]($style) )" +style = "yellow" + +[nodejs] +format = "[$symbol($version)]($style) " + +[bun] +format = "[$symbol($version)]($style) " + +[deno] +format = "[$symbol($version)]($style) " + +[python] +format = "[$symbol$pyenv_prefix($version)( \\($virtualenv\\))]($style) " + +[golang] +format = "[$symbol($version)]($style) " + +[ruby] +format = "[$symbol($version)]($style) " + +[cmd_duration] +min_time = 2_000 +format = "[$duration]($style) " +style = "yellow" + +[jobs] +format = "[$symbol$number]($style) " + +[character] +success_symbol = "[❯](bold green)" +error_symbol = "[❯](bold red)" +vimcmd_symbol = "[❮](bold green)" diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index 9093621..57930c1 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -1 +1,13 @@ alias vim="nvim" +alias dotfiles='cd "$DOTFILES_DIR"' + +if command -v eza >/dev/null 2>&1; then + alias ls="eza --group-directories-first --icons=auto" + alias ll="eza --group-directories-first --icons=auto --long --git --header" + alias la="eza --group-directories-first --icons=auto --long --git --header --all" + alias lt="eza --group-directories-first --icons=auto --tree --level=2" +fi + +if command -v bat >/dev/null 2>&1; then + alias cat="bat --paging=never --style=plain" +fi diff --git a/zsh/completion.zsh b/zsh/completion.zsh new file mode 100644 index 0000000..164bce2 --- /dev/null +++ b/zsh/completion.zsh @@ -0,0 +1,30 @@ +# Homebrew's site-functions are added in path.zsh; this adds zsh-completions. +if [[ -n "${HOMEBREW_PREFIX:-}" && -d "$HOMEBREW_PREFIX/share/zsh-completions" ]]; then + fpath=("$HOMEBREW_PREFIX/share/zsh-completions" $fpath) +fi + +zmodload zsh/complist +autoload -Uz compinit + +# Rebuild and security-check the completion dump at most once a day. -i skips insecure +# entries instead of prompting; Homebrew's group-writable share/ would otherwise trigger it. +() { + setopt local_options extended_glob + local dump="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/zcompdump-$ZSH_VERSION" + [[ -d "${dump:h}" ]] || mkdir -p "${dump:h}" + + if [[ -f "$dump" && -z $dump(#qN.mh+24) ]]; then + compinit -C -d "$dump" + else + compinit -i -d "$dump" + touch "$dump" + fi +} + +zstyle ':completion:*' menu select +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*' +zstyle ':completion:*' list-colors '' +zstyle ':completion:*' group-name '' +zstyle ':completion:*:descriptions' format '%F{yellow}%d%f' +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zsh/compcache" diff --git a/zsh/exports.zsh b/zsh/exports.zsh index de9e715..97a5292 100644 --- a/zsh/exports.zsh +++ b/zsh/exports.zsh @@ -1,11 +1,9 @@ export DOTFILES_DIR="${DOTFILES_DIR:-$HOME/dotfiles}" -export ZSH="${ZSH:-$HOME/.oh-my-zsh}" -export ZSH_THEME="${ZSH_THEME:-powerlevel10k/powerlevel10k}" -export DISABLE_UNTRACKED_FILES_DIRTY="true" export EDITOR="${EDITOR:-nvim}" export VISUAL="${VISUAL:-$EDITOR}" -export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" -export PYENV_ROOT="${PYENV_ROOT:-$HOME/.pyenv}" export PNPM_HOME="${PNPM_HOME:-$HOME/Library/pnpm}" + +export HOMEBREW_NO_ANALYTICS=1 +export HOMEBREW_NO_ENV_HINTS=1 diff --git a/zsh/options.zsh b/zsh/options.zsh new file mode 100644 index 0000000..009ed9c --- /dev/null +++ b/zsh/options.zsh @@ -0,0 +1,34 @@ +HISTFILE="$HOME/.zsh_history" +# HISTSIZE must exceed SAVEHIST for hist_expire_dups_first to have room to work. +HISTSIZE=120000 +SAVEHIST=100000 + +setopt extended_history share_history hist_expire_dups_first hist_ignore_dups +setopt hist_ignore_space hist_verify hist_reduce_blanks + +setopt auto_cd auto_pushd pushd_ignore_dups pushd_minus +setopt interactive_comments long_list_jobs no_flow_control +setopt complete_in_word always_to_end + +bindkey -e + +# Up/Down search history for commands starting with what is already typed. +autoload -Uz up-line-or-beginning-search down-line-or-beginning-search edit-command-line +zle -N up-line-or-beginning-search +zle -N down-line-or-beginning-search +zle -N edit-command-line + +bindkey '^[[A' up-line-or-beginning-search +bindkey '^[OA' up-line-or-beginning-search +bindkey '^[[B' down-line-or-beginning-search +bindkey '^[OB' down-line-or-beginning-search +bindkey '^X^E' edit-command-line + +# Word and line movement with Option/Ctrl + arrows, Home/End and forward delete. +bindkey '^[[1;3C' forward-word +bindkey '^[[1;3D' backward-word +bindkey '^[[1;5C' forward-word +bindkey '^[[1;5D' backward-word +bindkey '^[[H' beginning-of-line +bindkey '^[[F' end-of-line +bindkey '^[[3~' delete-char diff --git a/zsh/path.zsh b/zsh/path.zsh index d2576d3..2ec2b94 100644 --- a/zsh/path.zsh +++ b/zsh/path.zsh @@ -1,14 +1,19 @@ +typeset -U path fpath + +# Static equivalent of `brew shellenv`, which costs ~100 ms on every shell start. if [[ -x /opt/homebrew/bin/brew ]]; then - eval "$(/opt/homebrew/bin/brew shellenv)" + export HOMEBREW_PREFIX="/opt/homebrew" + export HOMEBREW_REPOSITORY="/opt/homebrew" elif [[ -x /usr/local/bin/brew ]]; then - eval "$(/usr/local/bin/brew shellenv)" + export HOMEBREW_PREFIX="/usr/local" + export HOMEBREW_REPOSITORY="/usr/local/Homebrew" fi -[[ -d "$PYENV_ROOT/bin" ]] && export PATH="$PYENV_ROOT/bin:$PATH" -[[ -d "$DOTFILES_DIR/bin" ]] && export PATH="$DOTFILES_DIR/bin:$PATH" -[[ -d "$HOME/.local/bin" ]] && export PATH="$HOME/.local/bin:$PATH" +if [[ -n "${HOMEBREW_PREFIX:-}" ]]; then + export HOMEBREW_CELLAR="$HOMEBREW_PREFIX/Cellar" + export INFOPATH="$HOMEBREW_PREFIX/share/info:${INFOPATH:-}" + path=("$HOMEBREW_PREFIX/bin" "$HOMEBREW_PREFIX/sbin" $path) + fpath=("$HOMEBREW_PREFIX/share/zsh/site-functions" $fpath) +fi -case ":$PATH:" in - *":$PNPM_HOME:"*) ;; - *) export PATH="$PNPM_HOME:$PATH" ;; -esac +path=("$HOME/.local/bin" "$PNPM_HOME" $path) diff --git a/zsh/plugins.zsh b/zsh/plugins.zsh index 237281a..d6712fe 100644 --- a/zsh/plugins.zsh +++ b/zsh/plugins.zsh @@ -1,23 +1,8 @@ -plugins=(git zsh-autosuggestions zsh-syntax-highlighting) +[[ -n "${HOMEBREW_PREFIX:-}" ]] || return 0 -source "$ZSH/oh-my-zsh.sh" +[[ -r "$HOMEBREW_PREFIX/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ]] && + source "$HOMEBREW_PREFIX/share/zsh-autosuggestions/zsh-autosuggestions.zsh" -if [[ -s "$NVM_DIR/nvm.sh" ]]; then - . "$NVM_DIR/nvm.sh" -fi - -if [[ -s "$NVM_DIR/bash_completion" ]]; then - . "$NVM_DIR/bash_completion" -fi - -if command -v pyenv >/dev/null 2>&1; then - eval "$(pyenv init - --no-rehash)" -fi - -if command -v rbenv >/dev/null 2>&1; then - eval "$(rbenv init - zsh)" -fi - -if [[ -o interactive ]] && command -v gh >/dev/null 2>&1; then - eval "$(gh copilot alias -- zsh 2>/dev/null)" || true -fi +# Must be the last plugin sourced. +[[ -r "$HOMEBREW_PREFIX/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]] && + source "$HOMEBREW_PREFIX/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" diff --git a/zsh/tools.zsh b/zsh/tools.zsh new file mode 100644 index 0000000..55f810a --- /dev/null +++ b/zsh/tools.zsh @@ -0,0 +1,43 @@ +# Every `eval "$(tool init)"` forks a process, which adds up to ~100 ms per shell. +# Cache each generated script, keyed by the tool's resolved binary path, so an +# upgrade (new Cellar path) regenerates it automatically. +_cached_init() { + local name="$1" bin="${commands[$2]}" + shift 2 + [[ -n "$bin" ]] || return 1 + + local dir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/init" + local cache="$dir/$name-${${bin:A}//\//_}.zsh" + + if [[ ! -s "$cache" ]]; then + [[ -d "$dir" ]] || mkdir -p "$dir" + rm -f "$dir/$name-"*.zsh(N) + "$@" >| "$cache" 2>/dev/null || { rm -f "$cache"; return 1; } + fi + + source "$cache" +} + +_cached_init mise mise mise activate zsh +_cached_init starship starship starship init zsh --print-full-init +_cached_init zoxide zoxide zoxide init zsh + +if (( $+commands[fzf] )); then + if (( $+commands[fd] )); then + export FZF_DEFAULT_COMMAND="fd --type file --hidden --follow --exclude .git" + export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" + export FZF_ALT_C_COMMAND="fd --type directory --hidden --follow --exclude .git" + fi + + if (( $+commands[bat] )); then + export FZF_CTRL_T_OPTS="--preview 'bat --color=always --style=numbers --line-range=:200 {}'" + fi + + _cached_init fzf fzf fzf --zsh +fi + +if (( $+commands[bat] )); then + export MANPAGER="sh -c 'col -bx | bat --language=man --plain'" +fi + +unfunction _cached_init diff --git a/zsh/zprofile b/zsh/zprofile new file mode 100644 index 0000000..3aacd37 --- /dev/null +++ b/zsh/zprofile @@ -0,0 +1,9 @@ +# Login shells, including non-interactive ones started by GUI apps and editors. +# Interactive shells also read ~/.zshrc, which activates mise fully. +export DOTFILES_DIR="${DOTFILES_DIR:-$HOME/dotfiles}" + +source "$DOTFILES_DIR/zsh/exports.zsh" +source "$DOTFILES_DIR/zsh/path.zsh" + +# Shims make mise-managed tools resolvable without the interactive prompt hook. +path=("${MISE_DATA_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/mise}/shims" $path) diff --git a/zsh/zshrc b/zsh/zshrc index e103cd9..b67203d 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -1,14 +1,13 @@ -# Enable Powerlevel10k instant prompt. Keep this near the top of ~/.zshrc. -if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then - source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" -fi - export DOTFILES_DIR="${DOTFILES_DIR:-$HOME/dotfiles}" source "$DOTFILES_DIR/zsh/exports.zsh" source "$DOTFILES_DIR/zsh/path.zsh" -source "$DOTFILES_DIR/zsh/plugins.zsh" +source "$DOTFILES_DIR/zsh/options.zsh" +source "$DOTFILES_DIR/zsh/completion.zsh" +source "$DOTFILES_DIR/zsh/tools.zsh" source "$DOTFILES_DIR/zsh/aliases.zsh" -[[ -f "$HOME/.p10k.zsh" ]] && source "$HOME/.p10k.zsh" [[ -f "$HOME/.zshrc.local" ]] && source "$HOME/.zshrc.local" + +# Syntax highlighting wraps every widget defined before it, so plugins load last. +source "$DOTFILES_DIR/zsh/plugins.zsh" From c5e549df92f09ac5b70a23bb98b18c415001bf52 Mon Sep 17 00:00:00 2001 From: conuko <50672977+conuko@users.noreply.github.com> Date: Mon, 2 Nov 2026 21:31:37 +0100 Subject: [PATCH 2/2] feat: install mise from mise.run and document shell shortcuts - Install mise with the official installer instead of Homebrew: the binary is 134 MB instead of 223 MB, slightly faster, and updates via `mise self-update` - Key the cached init scripts on binary mtime too, so self-updates refresh them - Document the fzf, zoxide, eza, bat and delta shortcuts in the README Co-Authored-By: Claude Opus 5.5 --- Brewfile | 4 ++-- README.md | 39 ++++++++++++++++++++++++++++++++++++--- bin/bootstrap | 15 ++++++++++++--- bin/update | 5 +++-- zsh/tools.zsh | 11 ++++++++--- 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Brewfile b/Brewfile index db436d6..4f4d177 100644 --- a/Brewfile +++ b/Brewfile @@ -19,8 +19,8 @@ brew "fd" brew "ripgrep" brew "jq" -# Development (language runtimes are managed by mise, see mise/config.toml) -brew "mise" +# Development (language runtimes are managed by mise, see mise/config.toml; +# mise itself comes from https://mise.run, installed by bin/bootstrap) brew "uv" brew "neovim" brew "shellcheck" diff --git a/README.md b/README.md index f409509..9cdbf22 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ The scripts are not on `PATH`; call them by path. ### Bootstrap a machine -Installs Homebrew and the tracked packages, links managed dotfiles, creates missing local files, installs mise runtimes, and optionally applies macOS defaults. +Installs Homebrew and the tracked packages, links managed dotfiles, creates missing local files, installs mise from [mise.run](https://mise.run) along with its runtimes, and optionally applies macOS defaults. ```bash ~/dotfiles/bin/bootstrap @@ -63,7 +63,7 @@ Safely backs up conflicting existing files in `~/.dotfiles-backups//` ### Update everything -Pulls the repo (`--ff-only`), upgrades Homebrew packages and mise runtimes, upgrades `gh` extensions, relinks, and lists installed packages that no Brewfile mentions. +Pulls the repo (`--ff-only`), upgrades Homebrew packages, mise itself (`mise self-update`) and its runtimes, upgrades `gh` extensions, relinks, and lists installed packages that no Brewfile mentions. ```bash ~/dotfiles/bin/update @@ -100,6 +100,39 @@ Commits and tags are signed with SSH (`gpg.format = ssh`). On a new machine: 2. Run `~/dotfiles/bin/bootstrap` (or create `~/.config/git/allowed_signers` yourself). 3. Add the public key as a **signing** key on GitHub (`gh ssh-key add ~/.ssh/id_ed25519.pub --type signing`) and on GitLab (key usage "Authentication & Signing"). +## Shell shortcuts + +### Keys + +| Keys | What it does | +| --- | --- | +| `Ctrl-R` | Fuzzy-search your command history (fzf) | +| `Ctrl-T` | Fuzzy-find a file below the current directory and insert its path, with a `bat` preview | +| `Alt-C` | Fuzzy-find a directory below the current one and `cd` into it | +| `**` then `Tab` | Fuzzy completion: `vim **` for files, `cd src/**` for directories, `kill **` for processes, `ssh **` for hosts | +| `Tab` | Completion menu with case-insensitive matching; move through it with the arrow keys | +| `↑` / `↓` | Step through earlier commands that start with what you have typed | +| `→` or `End` | Accept the grey autosuggestion; `Option-→` accepts one word of it | +| `Option-←` / `Option-→` | Move one word left or right (`Ctrl-←` / `Ctrl-→` work too) | +| `Ctrl-X Ctrl-E` | Edit the current command in Neovim | + +`Alt` is the left `Option` key in Ghostty (`macos-option-as-alt = left`). In iTerm, set the left Option key to "Esc+" under Profiles → Keys. + +### Commands + +| Command | What it does | +| --- | --- | +| `z ` | Jump to the most-used directory that matches (zoxide) | +| `zi ` | Pick from the matching directories with fzf | +| `` | Typing a directory name on its own `cd`s into it | +| `cd -` | Pick from recently visited directories | +| `ls`, `ll`, `la`, `lt` | eza: list, long list with git status, long list including hidden files, tree two levels deep | +| `cat ` | `bat` with syntax highlighting. Use `\cat` for the original: `bat` rejects flags such as `cat -v` | +| `man ` | Man pages are colored by `bat` | +| `vim` | Neovim | +| `dotfiles` | `cd` into this repo | +| `git diff`, `git show`, `git add -p` | Output goes through delta; `n` and `N` jump between files | + ## Runtimes with mise Global versions live in `mise/config.toml`. In a project, mise reads `mise.toml` or the version files of other managers (`.nvmrc` and friends) and switches versions when you `cd` into it, so there is no `nvm use` step. @@ -145,7 +178,7 @@ Requires `glab` on `PATH` with access to the GitLab project. ## Brewfile scope -The tracked `Brewfile` contains the core daily tools, grouped by purpose: Git (`git`, `git-lfs`, `git-delta`, `gh`, `glab`, `lazygit`), shell (`starship`, zsh plugins, `fzf`, `zoxide`, `eza`, `bat`, `fd`, `ripgrep`, `jq`), development (`mise`, `uv`, `neovim`, `shellcheck`), media and web (`ffmpeg`, `svgo`, `mkcert`), and the Ghostty cask. Language runtimes come from mise, not Homebrew. +The tracked `Brewfile` contains the core daily tools, grouped by purpose: Git (`git`, `git-lfs`, `git-delta`, `gh`, `glab`, `lazygit`), shell (`starship`, zsh plugins, `fzf`, `zoxide`, `eza`, `bat`, `fd`, `ripgrep`, `jq`), development (`uv`, `neovim`, `shellcheck`), media and web (`ffmpeg`, `svgo`, `mkcert`), and the Ghostty cask. Language runtimes come from mise, not Homebrew. mise itself is installed from [mise.run](https://mise.run) into `~/.local/bin`, because the official binary is smaller and faster than Homebrew's build and can update itself. Put extra machine-local packages in the untracked `Brewfile.local`; `bin/bootstrap` and `bin/update` load it when it exists. diff --git a/bin/bootstrap b/bin/bootstrap index b6a6faf..cb0abe5 100755 --- a/bin/bootstrap +++ b/bin/bootstrap @@ -50,6 +50,16 @@ copy_if_missing() { echo "Created: $target" } +# The official binary is smaller and faster than Homebrew's build and can update itself. +ensure_mise() { + if [[ -x "$HOME/.local/bin/mise" ]]; then + return 0 + fi + + echo "Installing mise..." + curl -fsSL https://mise.run | MISE_INSTALL_HELP=0 sh +} + install_brewfile_if_present() { local brewfile="$1" @@ -93,9 +103,8 @@ copy_if_missing "$ROOT/local/gitconfig.example" "$HOME/.gitconfig" copy_if_missing "$ROOT/local/zshrc.local.example" "$HOME/.zshrc.local" ensure_allowed_signers -if command -v mise >/dev/null 2>&1; then - mise install -fi +ensure_mise +"$HOME/.local/bin/mise" install if [[ $RUN_MACOS -eq 1 ]]; then "$ROOT/bin/macos" diff --git a/bin/update b/bin/update index 93f2cf8..8d6bb1a 100755 --- a/bin/update +++ b/bin/update @@ -27,8 +27,9 @@ fi "$ROOT/bin/link" -if command -v mise >/dev/null 2>&1; then - mise upgrade +if [[ -x "$HOME/.local/bin/mise" ]]; then + "$HOME/.local/bin/mise" self-update --yes + "$HOME/.local/bin/mise" upgrade fi if command -v gh >/dev/null 2>&1; then diff --git a/zsh/tools.zsh b/zsh/tools.zsh index 55f810a..1d7b678 100644 --- a/zsh/tools.zsh +++ b/zsh/tools.zsh @@ -1,13 +1,18 @@ # Every `eval "$(tool init)"` forks a process, which adds up to ~100 ms per shell. -# Cache each generated script, keyed by the tool's resolved binary path, so an -# upgrade (new Cellar path) regenerates it automatically. +# Cache each generated script, keyed by the tool's resolved binary path and its +# modification time, so an upgrade (`brew upgrade`, `mise self-update`) regenerates it. +zmodload -F zsh/stat b:zstat + _cached_init() { local name="$1" bin="${commands[$2]}" shift 2 [[ -n "$bin" ]] || return 1 + local -a mtime + zstat -A mtime +mtime -- "${bin:A}" || return 1 + local dir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/init" - local cache="$dir/$name-${${bin:A}//\//_}.zsh" + local cache="$dir/$name-${${bin:A}//\//_}-${mtime[1]}.zsh" if [[ ! -s "$cache" ]]; then [[ -d "$dir" ]] || mkdir -p "$dir"