macos/defaults/keyboard.sh

#!/usr/bin/env bash
# macos/defaults/keyboard.sh — keyboard repeat + caps-lock remap.

set -euo pipefail

[[ "$OSTYPE" == darwin* ]] || { printf 'keyboard.sh: macOS only\n' >&2; exit 1; }

# Aggressive key-repeat, short initial delay.
defaults write NSGlobalDomain KeyRepeat         -int 2
defaults write NSGlobalDomain InitialKeyRepeat  -int 15

# Disable press-and-hold for accented characters so key repeat actually works.
defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

# Full keyboard access: Tab cycles through all controls, not just text boxes.
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

# Disable smart quotes / dashes / autocorrect (annoying in code).
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled  -bool false
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled   -bool false
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false
defaults write NSGlobalDomain NSAutomaticCapitalizationEnabled     -bool false
defaults write NSGlobalDomain NSAutomaticPeriodSubstitutionEnabled -bool false

# Remap Caps Lock -> Control using hidutil.
# 0x700000039 = Caps Lock, 0x7000000E0 = Left Control.
hidutil property --set '{
  "UserKeyMapping": [{
    "HIDKeyboardModifierMappingSrc": 0x700000039,
    "HIDKeyboardModifierMappingDst": 0x7000000E0
  }]
}' >/dev/null

printf 'keyboard: repeat tuned, caps-lock -> control. Log out + back in to fully apply.\n'