cmd / laptop
I maintain a laptop repo that configures a macOS machine as a software development environment.
Install
export LAPTOP="$HOME/laptop"
git clone https://github.com/croaky/laptop.git $LAPTOP
cd $LAPTOP
./laptop.sh
The script resolves ~/laptop from git's common directory, so
symlinks survive when a merge deletes a
change worktree. Dotfile edits take effect after
merge and git pull in ~/laptop.
What it sets up
The script is idempotent. I run it on macOS on Apple Silicon. It:
- installs system packages with Homebrew
- sets the login shell to Homebrew bash 5 with
bash-completion@2 - symlinks dotfiles to
$HOME - changes macOS settings and adds window shortcuts
- installs Go, Rust, and Go tools: deadcode, goimports, gopls
- installs tsgo, dprint, and stylua as single binaries
- installs CLIs: awscli, bat, cb, fd, fzf, gh, git, ripgrep, tree, ubi
- installs my own commands, such as browse, from
main(see go / checks) - manages local apps and blocks trackers in
/etc/hostswith hostctl - sets up Neovim
- starts Postgres dev and test clusters
macOS settings
The script turns off all four hot corners so a dragged screenshot does not open Mission Control; F3 still opens it. It also turns off "Click wallpaper to reveal desktop" so a drag across the wallpaper does not scatter windows. It writes each setting only when its value differs.
Window shortcuts
Every macOS app has Left, Right, and Fill in its "Window > Move & Resize" menu. The script gives them keys as App Shortcuts, so I use no window manager app:
- Control-Option-Left: Left (left half)
- Control-Option-Right: Right (right half)
- Control-Option-Return: Fill (full screen area)
defaults write -g NSUserKeyEquivalents -dict-add \
"Left" '^~\UF702' \
"Right" '^~\UF703' \
"Fill" '^~\U21A9'
^ is Control and ~ is Option. defaults reads \UF702, \UF703,
and \U21A9 as the left arrow, right arrow, and return keys. An app
reads the shortcuts when it starts. Fill does not go back to the old
size. "Window > Move & Resize > Return to Previous Size" does that.
Editor formatting
Neovim formats Go with goimports, Lua with stylua, and SQL with pgfmt on save. In a repo I trust, Neovim runs the version that the file's module pins, the same version that the repo's checks run (see go / checks). So a version bump in a repo needs no change in this repo.
To stop an untrusted clone from running repo-chosen tools on save, I
gate them with git trust. In an untrusted repo,
format-on-save uses my global dprint config and installed goimports,
and skips pgfmt. shell/bashrc and vim/init.lua strip relative
entries from PATH, package.path, and package.cpath so entering a
repo or saving a file cannot run local binaries or Lua modules.
For SQL in a trusted repo, Neovim runs go tool pgfmt in the
directory of the file's go.mod. A module that does not pin pgfmt
gets no SQL formatting on save. For Go, a script runs
go tool -modfile=tools.mod goimports in a library and
go tool goimports in an app. A module that pins neither gets the
goimports that this script installs.
The repo commits Neovim's lazy-lock.json, and vim/sync-plugins.sh
clones and verifies every plugin at its locked commit before Neovim
starts. A missing lockfile entry or missing commit stops laptop.sh
and leaves no unverified plugin directory on disk.
No JavaScript runtime
The machine has no node, npm, or bun. tsgo, dprint, esbuild's Go API, and native language servers cover what those ran. See web / no js runtime for the native toolchain.
Hosts file
hostctl manages /etc/hosts for local development and DNS-level ad blocking.
laptop.sh runs it.
Local apps
Browsers treat http://localhost and http://*.localhost as
potentially trustworthy origins,
so Secure Context features work without TLS.
I run apps on different subdomains and ports
(site.localhost:2000, htmz.localhost:2002) to test
cross-origin security:
SameSite=StrictcookiesSec-Fetch-Site: same-originandOriginheadersReferrer-Policy: strict-origin-when-cross-originheader
Ad blocking
A hosts file blocks ads and trackers across every app on the laptop.
hostctl enables blocking by default:
hostctl
To disable blocking while keeping local app entries:
hostctl --unblock
hostctl filters the downloaded list before it writes /etc/hosts.
It keeps only 0.0.0.0 <name> lines with a valid host name, and it
drops localhost, broadcasthost, and *.localhost. The remote site
can block a name, and it cannot redirect a name to an address that it
chooses. If the download fails or the filter keeps zero lines,
hostctl stops and leaves /etc/hosts unchanged.
Core script logic:
#!/bin/bash
set -euo pipefail
url=https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
if [[ "${1:-}" == "--unblock" ]]; then
local_hosts_entries | sudo tee /etc/hosts >/dev/null
else
tmp=$(mktemp -d)
trap 'rm -rf -- "$tmp"' EXIT
curl -fsS -o "$tmp/download" "$url"
hostctl_filter "$tmp/download" >"$tmp/blocked"
[ -s "$tmp/blocked" ] || exit 1
{
local_hosts_entries
echo
cat "$tmp/blocked"
} >"$tmp/hosts"
sudo tee /etc/hosts <"$tmp/hosts" >/dev/null
fi
sudo killall -HUP mDNSResponder
The script holds the local app entries, so no other file has a copy.
Server configuration
A Go server binds to a port, and the hosts file resolves the subdomain:
fmt.Println("Serving at http://site.localhost:2000")
http.ListenAndServe("127.0.0.1:2000", handler)
Binding to 127.0.0.1 keeps the local development server off the local
network. I use the 2000 port range for Go servers and 3000 for Ruby
servers.