Day 0: Setting up the training ground
Goal: All tools are in place,
~/term-labexists, the practice zsh starts in isolation. · Duration: approx. 30 min · Prerequisite: none
Briefing
- Everything runs on a Mac with Apple Silicon. Homebrew lives under
/opt/homebrew, the default shell is zsh. - The tools are listed in a
Brewfile. One command checks, one command installs. - Your practice home is
~/term-lab. The practice zsh reads its configuration from~/term-lab/zshinstead of~. - The practice project
~/term-lab/projektis a small Git repo with Go, Python, YAML and logs. - A Nerd Font provides the symbols for the prompt,
ezaand Neovim.
~/term-lab/
├── lab start script: open the practice zsh
├── zsh/ ZDOTDIR: .zshenv, .zshrc, .zsh_history
├── config/zsh/ your own *.zsh files (from Day 5)
├── config/starship.toml
├── tmux.conf (from Day 8)
├── gitconfig GIT_CONFIG_GLOBAL for the drills
├── bin/ your own scripts, on the PATH
└── projekt/ practice project "shop" (Git repo)
Drill 1: Checking the system
sw_vers -productVersion
uname -m
echo $SHELL
zsh --version
brew --prefixExpected (may differ depending on version):
15.6.1
arm64
/bin/zsh
zsh 5.9 (arm64-apple-darwin24.0)
/opt/homebrew
If uname -m shows x86_64, your terminal is
running under Rosetta. Then Homebrew lives under
/usr/local. Check in the terminal app’s Get Info window in
the Finder whether “Open using Rosetta” is enabled.
Save your progress? Sign up for free
Drill 2: The Brewfile
The companion material is on GitHub. Get it and remember the path in a variable:
git clone https://github.com/thomaszachmann/mac-terminal-zum-anfassen.git \
~/mac-terminal-zum-anfassen
export BUCH=~/mac-terminal-zum-anfassen
ls $BUCH/brew $BUCH/setupExpected:
Cloning into '/Users/du/mac-terminal-zum-anfassen'...
/Users/du/mac-terminal-zum-anfassen/brew:
Brewfile
/Users/du/mac-terminal-zum-anfassen/setup:
projekt-dateien.sh term-lab-setup.sh
An excerpt from the Brewfile:
cask "iterm2"
cask "ghostty"
cask "font-jetbrains-mono-nerd-font"
brew "tmux"
brew "starship"
brew "fzf"
brew "tlrc" # liefert den Befehl tldr
brew "kubectx" # liefert kubectx und kubens
First check, install nothing:
brew bundle check --verbose --file=$BUCH/brew/BrewfileExpected (shortened, depends on your Mac):
brew bundle can't satisfy your Brewfile's dependencies.
→ Cask ghostty needs to be installed or updated.
→ Formula starship needs to be installed or updated.
→ Formula tlrc needs to be installed or updated.
→ Formula httpie needs to be installed or updated.
→ Formula entr needs to be installed or updated.
Satisfy missing dependencies with `brew bundle install`.
“installed or updated” means: missing or outdated. Now install, without upgrading what’s already there:
brew bundle install --no-upgrade --file=$BUCH/brew/Brewfile
brew bundle check --file=$BUCH/brew/BrewfileExpected (shortened, may differ depending on version):
Installing ghostty
Installing starship
...
`brew bundle` complete! 32 Brewfile dependencies now installed.
The Brewfile's dependencies are satisfied.
Why --no-upgrade? A lab setup shouldn’t casually bump
your work tools to new major versions. Upgrading is a deliberate
decision (Day 13).
Tip: The Brewfile is your first piece of “Mac as code”. On Day 13 you’ll generate it from your real system with
brew bundle dump.
Save your progress? Sign up for free
Drill 3: Creating the practice home
The setup script creates ~/term-lab. It touches neither
~/.zshrc nor ~/.gitconfig:
bash $BUCH/setup/term-lab-setup.shExpected:
✔ projekt: 4 Commits, 500 Logzeilen
✔ Übungs-Home: /Users/du/term-lab
Start: /Users/du/term-lab/lab
A second run changes nothing. The script is idempotent:
bash $BUCH/setup/term-lab-setup.shExpected:
projekt existiert schon – unverändert (neu bauen mit --reset)
✔ Übungs-Home: /Users/du/term-lab
Start: /Users/du/term-lab/lab
The core is the start script ~/term-lab/lab:
cat ~/term-lab/labExpected:
#!/bin/sh
# Startet die Übungs-zsh. Die echte ~/.zshrc bleibt unberührt.
LAB="${LAB:-$HOME/term-lab}"
exec env LAB="$LAB" ZDOTDIR="$LAB/zsh" zsh -i "$@"
Why ZDOTDIR? zsh looks for .zshenv,
.zshrc and .zsh_history in
$ZDOTDIR. If the variable isn’t set, zsh uses
$HOME. Redirecting HOME would be more
dangerous: then git, ssh and every other tool would no longer find their
configuration either.
Save your progress? Sign up for free
Drill 4: Starting the practice zsh
~/term-lab/lab
echo $ZDOTDIR
echo $HISTFILE
echo $GIT_CONFIG_GLOBAL
git config user.nameExpected:
[lab] ~ % echo $ZDOTDIR
/Users/du/term-lab/zsh
/Users/du/term-lab/zsh/.zsh_history
/Users/du/term-lab/gitconfig
Lab User
The yellow [lab] prefix always tells you that you’re in
the practice home. Your history lands in its own file. Git uses the lab
configuration.
Which files did this zsh read at startup? The
sourcetrace option tells you:
ZDOTDIR=~/term-lab/zsh zsh -o sourcetrace -i -c exitExpected:
+/Users/du/term-lab/zsh/.zshenv:1> <sourcetrace>
+/etc/zshrc:1> <sourcetrace>
+/Users/du/term-lab/zsh/.zshrc:1> <sourcetrace>
No trace of ~/.zshrc. That’s exactly what we want. With
exit or ⌃D you get back to your normal
shell.
Warning: If you open a new window or a new tab, you’re back in your real shell. Type
~/term-lab/labagain then. On Day 1 you’ll build your own terminal profile for this.
Save your progress? Sign up for free
Drill 5: Exploring the practice project
cd ~/term-lab/projekt
git log --oneline --graph --all --decorate
git branchExpected:
* 375fbf7 (feature/rabatt) feat: Rabatt-Schalter
* 2e4e6aa (HEAD -> main) chore: Config, Manifeste, Report
* a57983c feat: Warenkorb und HTTP-Server
* 1dc0abc init: Projektgerüst
feature/rabatt
* main
The commits have fixed dates and the author “Lab User”. That’s why you see the same hashes as in the book.
find . -path ./.git -prune -o -type f -print | sortExpected:
./.gitignore
./cmd/shop/main.go
./config/app.json
./config/app.yaml
./deploy/k8s/deployment.yaml
./docs/notizen.txt
./go.mod
./internal/cart/cart.go
./logs/access.log
./logs/app.log
./README.md
./scripts/report.py
The logs are listed in .gitignore. That’s on purpose: on
Day 6 you’ll see why rg doesn’t find them.
python3 scripts/report.py
grep -rn TODO --include='*.go' --include='*.py' .Expected:
INFO 350
WARN 50
ERROR 50
DEBUG 50
internal/cart/cart.go:16: // TODO: Rabatte berücksichtigen
cmd/shop/main.go:13: port = "8080" // TODO: aus config/app.yaml lesen
scripts/report.py:13:# TODO: als JSON ausgeben
Save your progress? Sign up for free
Drill 6: Checking the Nerd Font
A Nerd Font is a normal programming font plus several thousand
symbols: Git branch, folder, language logos, Powerline arrows. The
prompt, eza --icons and Neovim need it.
ls ~/Library/Fonts | grep -E 'JetBrainsMonoNerdFont(Mono)?-Regular'
brew list --cask --versions font-jetbrains-mono-nerd-fontExpected (may differ depending on version):
JetBrainsMonoNerdFont-Regular.ttf
JetBrainsMonoNerdFontMono-Regular.ttf
font-jetbrains-mono-nerd-font 3.4.0
The NerdFontMono variant has strictly single-width
symbols. It fits terminals best. Now the visual test:
printf ' \U000f0219 \n'Expected: five symbols (arrow, Git branch, folder, document, branch). If you see boxes or question marks, your terminal app isn’t using a Nerd Font yet. You’ll switch that on Day 1.
Save your progress? Sign up for free
Drill 7: Rebuilding and cleaning up
You’ve messed up the project? Then rebuild just the project. Your lab
configuration under zsh/ is kept:
bash $BUCH/setup/term-lab-setup.sh --resetExpected:
✔ projekt: 4 Commits, 500 Logzeilen
✔ Übungs-Home: /Users/du/term-lab
Start: /Users/du/term-lab/lab
Removing everything is just as easy, because there’s nothing outside
~/term-lab:
echo rm -rf ~/term-lab # look first, then run without echoSecurity: Get used to putting
echobeforerm -rfwith variables or~. Otherwise an empty$LABturnsrm -rf "$LAB/projekt"intorm -rf /projekt. The setup script protects itself withset -u.
Save your progress? Sign up for free
Shortcut table
| Key | Effect | Mnemonic |
|---|---|---|
⌃D |
exit the shell (on an empty line) | Done |
⌃C |
cancel the running command | Cancel |
⌃L |
clear the screen, the line stays | cLear |
⌘K |
clear the terminal app’s scrollback | Kill buffer |
⌘T / ⌘N |
new tab / new window | Tab, New |
Checkpoint
LAB=${LAB:-~/term-lab}
ok() { local m=$1; shift; "$@" >/dev/null 2>&1 && echo "✔ $m" || echo "✘ $m"; }
hist=$(env ZDOTDIR="$LAB/zsh" zsh -i -c 'echo $HISTFILE')
ok "Startskript" test -x "$LAB/lab"
ok "Lab-.zshrc" test -f "$LAB/zsh/.zshrc"
ok "Projekt-Repo" test "$(git -C "$LAB/projekt" rev-list --count --all)" = 4
ok "eigene History" test "$hist" = "$LAB/zsh/.zsh_history"
ok "Nerd Font" sh -c 'ls ~/Library/Fonts | grep -q NerdFont'
for t in tmux fzf rg fd bat eza zoxide atuin nvim jq gh; do
ok "Tool $t" command -v $t
doneExpected (shortened):
✔ Startskript
✔ Lab-.zshrc
✔ Projekt-Repo
✔ eigene History
✔ Nerd Font
✔ Tool tmux
...
✔ Tool gh
Challenge
Terminal apps on the Mac start the shell as a login shell. Start the practice zsh as a login shell and find out which startup file is read in addition.
Hint: man zsh, section STARTUP/SHUTDOWN
FILES, and the -l option.
Solution
ZDOTDIR=~/term-lab/zsh zsh -l -o sourcetrace -i -c exitExpected:
+/Users/du/term-lab/zsh/.zshenv:1> <sourcetrace>
+/etc/zprofile:1> <sourcetrace>
+/etc/zshrc:1> <sourcetrace>
+/Users/du/term-lab/zsh/.zshrc:1> <sourcetrace>
What’s new is /etc/zprofile. That’s where macOS calls
path_helper and builds the PATH from
/etc/paths and /etc/paths.d/. A
.zprofile of your own in ~/term-lab/zsh would
be read right after it. You’ll see on Day 2 why that matters for a clean
PATH.
Save your progress? Sign up for free
Enterprise Note
- On company Macs, MDM (Jamf, Intune, Kandji) often manages the
software. Check whether Homebrew is allowed and whether an internal
mirror or proxy (
HOMEBREW_ARTIFACT_DOMAIN,HTTPS_PROXY) is required. - Put the Brewfile in the team repo. New colleagues are then ready to
work in minutes with
brew bundle install. - Pin critical versions deliberately and upgrade in batches with
brew bundle installplus a changelog check, not casually. - Fonts and casks sometimes need admin rights. Clarify that before onboarding day, not during it.
- The “own practice home via
ZDOTDIR” pattern also works well for training sessions and pairing on other people’s machines: nothing gets overwritten, everything can be removed with a singlerm -rf.