Skip to content

snkrheadz/laptop

Repository files navigation

laptop

Personal macOS configuration management system with automated dotfiles synchronization, security scanning, and one-command setup/rollback capabilities.

Core Components

This repository manages configurations for the following applications:

Category Application Config Location
Shell Zsh + Oh-My-Zsh ~/.zshrc, ~/.zsh/
Terminal Ghostty ~/.config/ghostty/config
Editor Neovim, Vim via Homebrew
Version Control Git, Tig ~/.gitconfig, ~/.tigrc
Multiplexer tmux ~/.tmux.conf
Fuzzy Finder fzf ~/.fzf.zsh
Packages Homebrew Brewfile
Runtimes mise ~/.config/mise/config.toml
AI Assistant Claude Code ~/.claude/ (CLAUDE.md, hooks, agents)

Brewfile includes:

  • 100+ CLI tools (aws, gh, ripgrep, bat, jq, etc.)
  • 40+ GUI applications (Cursor, Ghostty, Arc, Raycast, etc.)
  • 80+ VSCode/Cursor extensions

Architecture

Symlink Strategy

Configuration files reside in this repository and symlink to their standard locations:

~/.zshrc          → laptop/zsh/.zshrc
~/.gitconfig      → laptop/git/.gitconfig
~/.config/ghostty → laptop/ghostty/config

Why symlinks?

  • Git tracks actual content, not just symlink paths
  • No specialized tooling required (stow, chezmoi, etc.)
  • Easy to understand and debug
  • Industry-standard approach

Directory Structure

laptop/
├── install.sh              # Main installer
├── rollback.sh             # Restore from backup
├── Brewfile                # Homebrew packages manifest
│
├── zsh/                    # Shell configuration
│   ├── .zshrc              # Main config (loads below in order)
│   ├── .aliases            # Shell aliases
│   ├── functions/          # Custom zsh functions
│   └── configs/            # Modular configs
│       ├── pre/            # Loaded first
│       ├── *.zsh           # Main configs (color, editor, history, etc.)
│       └── post/           # Loaded last (PATH, completion)
│
├── git/                    # Git configuration
│   ├── .gitconfig          # Main git config
│   ├── .gitignore          # Global gitignore
│   ├── .gitmessage         # Commit message template
│   └── .git_template/      # Git hooks template
│
├── ghostty/                # Ghostty terminal config
├── tmux/                   # tmux configuration
├── tig/                    # Tig (git TUI) config
├── fzf/                    # Fuzzy finder config
├── mise/                   # mise runtime manager config
├── claude/                 # Claude Code configuration
│   ├── CLAUDE.md           # User global instructions
│   ├── statusline.sh       # Custom status line script
│   ├── hooks/              # PostToolUse hooks
│   └── agents/             # Subagents
│
├── scripts/
│   └── auto-sync.sh        # Hourly auto-sync script
│
├── .pre-commit-config.yaml # Pre-commit hooks
├── .gitleaks.toml          # Secret scanning rules
└── .gitignore              # Security-focused ignore patterns

Security

Three-Layer Protection

  1. Pre-commit Hooks - Runs before every commit:

    • gitleaks - Scans for secrets and credentials
    • detect-private-key - Catches SSH/PGP keys
    • trailing-whitespace, end-of-file-fixer - Code hygiene
  2. Comprehensive .gitignore - Blocks 30+ sensitive patterns:

    • Environment files (.env, .secrets.env)
    • Cloud credentials (AWS, GCP, Azure)
    • SSH/GPG keys (id_rsa*, *.pem)
    • Terraform state (*.tfstate, *.tfvars)
  3. Secrets Template - API keys belong in ~/.secrets.env:

    # ~/.secrets.env (gitignored, created by install.sh)
    export OPENAI_API_KEY=""
    export ANTHROPIC_API_KEY=""
    export GITHUB_TOKEN=""

Security Scanning Commands

# Manual gitleaks scan
gitleaks detect --source=. --no-git

# Run all pre-commit hooks
pre-commit run --all-files

Automation

Auto-Sync (launchd)

An hourly launchd agent runs scripts/auto-sync.sh:

  1. Regenerates Brewfile from current installations
  2. Runs gitleaks scan (aborts if secrets detected)
  3. Executes pre-commit hooks
  4. Commits and pushes changes automatically

Log files:

  • ~/.dotfiles_autosync.log - Standard output
  • ~/.dotfiles_autosync.error.log - Errors

Manual sync:

./scripts/auto-sync.sh

Installation

New Machine Setup

# Clone repository
git clone https://github.com/snkrheadz/laptop.git ~/ghq/github.com/snkrheadz/laptop

# Run installer
cd ~/ghq/github.com/snkrheadz/laptop
./install.sh

What install.sh does:

  1. Checks macOS and installs Xcode CLI tools
  2. Installs Homebrew (if not present)
  3. Creates timestamped backup of existing configs
  4. Creates symlinks to repository configs
  5. Installs all Homebrew packages from Brewfile
  6. Sets up mise and installs runtimes (Go, Node.js, Python, Ruby)
  7. Sets up gitleaks + pre-commit hooks
  8. Configures launchd auto-sync agent
  9. Creates ~/.secrets.env template

Rollback

# List available backups
./rollback.sh

# Restore specific backup
./rollback.sh 20231223_120000

What rollback.sh does:

  1. Disables auto-sync launchd agent
  2. Removes all symlinks
  3. Restores files from backup

Update Packages

# Dump current installations to Brewfile
brew bundle dump --force --file=Brewfile

# Install packages from Brewfile
brew bundle --file=Brewfile

Runtime Management (mise)

mise manages programming language runtimes (Go, Node.js, Python, Ruby).

Installed Runtimes

Runtime Version
Go 1.24.3
Node.js 25.2.1
Python 3.13.x
Ruby 3.4.8

Commands

# List installed runtimes
mise list

# Install all runtimes from config
mise install

# Install specific runtime
mise use go@1.23.1

# Update to latest versions
mise upgrade

Configuration

Edit mise/config.toml to change versions:

[tools]
go = "1.24.3"
node = "25.2.1"
python = "3.13"
ruby = "3.4.8"

Customization

Local Overrides

Create ~/.zshrc_local for machine-specific settings (automatically sourced, not tracked):

# ~/.zshrc_local
export WORK_PROJECT_PATH="/path/to/work"
alias deploy="./scripts/deploy-work.sh"

Adding New Dotfiles

  1. Add config file to appropriate directory (e.g., tool/.toolrc)
  2. Update install.sh to create symlink:
    safe_ln "$DOTFILES_DIR/tool/.toolrc" "$HOME/.toolrc"
  3. Update rollback.sh symlinks array
  4. Commit and push

Development Notes

zsh Loading Order

1. zsh/functions/*        # Custom functions
2. zsh/configs/pre/*      # Pre-configs
3. zsh/configs/*.zsh      # Main configs
4. zsh/configs/post/*     # Post-configs (PATH, completion)
5. ~/.aliases             # Shell aliases
6. oh-my-zsh              # Plugins: git, zsh-autosuggestions

Avoiding Conflicts

  • Don't create functions with names that conflict with oh-my-zsh aliases
    • Example: g is already defined by the git plugin
  • Run alias after installation to check for conflicts

Symlink Safety

install.sh uses safe_ln() which removes existing symlinks before creating new ones. This prevents circular references when running install.sh multiple times.

Claude Code Configuration

This repository manages Claude Code settings via symlinks:

claude/
├── CLAUDE.md           # User global instructions → ~/.claude/CLAUDE.md
├── statusline.sh       # Custom status line script → ~/.claude/statusline.sh
├── hooks/
│   └── validate-shell.sh  # PostToolUse hook → ~/.claude/hooks/
└── agents/
    └── verify-shell.md    # Shell verification agent → ~/.claude/agents/

Managed Components

Component Description
CLAUDE.md User global instructions (workflow, best practices, prohibitions)
statusline.sh Custom status line showing model, cost, context
validate-shell.sh PostToolUse hook for shellcheck validation on .sh files
verify-shell.md Subagent for comprehensive shell script verification

Status Line

Displays in Claude Code CLI:

[Opus] 📁 laptop | 🌿 main | 💰 $5.20 (Today) | 📊 185k

Features:

  • Model name (Opus/Sonnet)
  • Current directory
  • Git branch
  • Daily cumulative cost
  • Context window remaining

Hooks

PostToolUse: validate-shell.sh

  • Triggers after Write or Edit tools
  • Runs shellcheck on .sh files
  • Blocks commit if issues found

Available Plugins

  • /commit-commands:commit-push-pr - Commit, push, and create PR in one command

Not Managed

~/.claude/settings.json is NOT managed (Claude auto-modifies it). Required hook config:

{
  "hooks": {
    "PostToolUse": [{
      "matcher": "Write|Edit",
      "hooks": [{"type": "command", "command": "~/.claude/hooks/validate-shell.sh"}]
    }]
  }
}

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •