Day 1: Setting up the terminal app
Goal: iTerm2 (or Ghostty) with a lab profile, Nerd Font, Option as Meta, splits and a hotkey window – all from the keyboard. · Duration: approx. 60 min · Prerequisite: Day 0
Briefing
- The terminal app is just the window. It draws characters, manages tabs and splits, and translates keys into bytes for the shell.
- iTerm2 is the proven standard on the Mac: profiles, hotkey window, shell integration. Ghostty is the fast, modern alternative with a text file as its configuration. WezTerm and Warp exist too. We don’t use them here.
- The most important setting of the day: Option as
Meta. Otherwise
⌥Btypes a∫instead of jumping back one word (Day 3). - ⌘ keys belong to the app, ⌃ and ⌥ keys to the shell.
Key ──► Terminal app ──(bytes)──► zsh / tmux / nvim
⌘D, ⌘T, ⌘F ⌃A, ⌃R, ⌥B, ⌥F
Drill 1: Who am I, what can I do?
echo "$TERM_PROGRAM $TERM_PROGRAM_VERSION"
echo "$TERM $COLORTERM"
tput colors
printf '\e[38;2;255;120;0mTruecolor\e[0m \e[1mfett\e[0m \e[3mkursiv\e[0m\n'Expected in iTerm2 (may differ depending on version):
iTerm.app 3.6.6
xterm-256color truecolor
256
Truecolor fett kursiv
The word “Truecolor” appears orange, “fett” (bold) in bold, “kursiv”
(italic) slanted. COLORTERM=truecolor tells programs like
Neovim and bat that they may use 16 million colors. In Ghostty you’ll
see ghostty there and TERM=xterm-ghostty.
Tip: The built-in Terminal.app is fine in an emergency. But it lacks splits, a hotkey window and profiles as code. For this book, use iTerm2 or Ghostty.
Save your progress? Sign up for free
Drill 2: A lab profile for iTerm2 as code
Instead of clicking through dialogs, you create a Dynamic Profile. iTerm2 reads JSON files from a fixed folder and shows them immediately as profiles. Delete the file and the profile is gone.
D=~/Library/Application\ Support/iTerm2/DynamicProfiles
mkdir -p "$D"
cat > "$D/term-lab.json" <<EOF
{
"Profiles": [
{
"Name": "term-lab",
"Guid": "term-lab-0001",
"Dynamic Profile Parent Name": "Default",
"Custom Command": "Yes",
"Command": "$HOME/term-lab/lab",
"Custom Directory": "Yes",
"Working Directory": "$HOME/term-lab/projekt",
"Normal Font": "JetBrainsMonoNFM-Regular 14",
"Option Key Sends": 2,
"Right Option Key Sends": 0,
"Unlimited Scrollback": true,
"Badge Text": "LAB",
"Tags": ["term-lab"]
}
]
}
EOF
jq -r '.Profiles[] | "\(.Name) -> \(.Command)"' "$D/term-lab.json"Expected:
term-lab -> /Users/du/term-lab/lab
Note the <<EOF without quotes. That way the shell
substitutes $HOME, because iTerm2 doesn’t understand
~. The numbers for Option Key Sends mean: 0 =
normal, 1 = Meta, 2 = Esc+. Esc+ on the left turns ⌥ into
the Meta key. The right one stays normal so you can still type
@, | and {.
Now open it: ⌘O (profile picker), type
term-lab, ⏎. The new window starts the
practice zsh directly in the project, with the yellow [lab]
and the badge “LAB” in the top right.
Tip: You can find a font’s PostScript name with
mdls -name com_apple_ats_name_postscript <datei.ttf>. For the Mono variant it’sJetBrainsMonoNFM-Regular.
Save your progress? Sign up for free
Drill 3: Checking Option as Meta
cat -v shows what a key really sends to the shell. Type
⌥B, ⌥F, ⌥. one after another and
then ⏎. Quit with ⌃C.
cat -vExpected in the lab profile:
^[b^[f^[.
^[ is Escape. So Esc+ sends “Escape, then b”. That’s
exactly what zsh understands as Meta-B. In the Default profile you’ll
see ∫ƒ… instead. Then ⌥ is still a character key.
Right after that, ⌃V and a key: zsh inserts the raw
character. That’s also how you find out the code for arrow keys:
# type: ⌃V ⌥← (without Enter)Expected (may differ depending on profile):
^[^[[D
This becomes important on Day 3, when you bind word jumps to ⌥← and ⌥→.
Save your progress? Sign up for free
Drill 4: The “Natural Text Editing” key mapping
Many Mac people expect ⌥← for “word back” and ⌘← for “start of line”. iTerm2 ships a preset for that:
⌘,opens Settings. Go to Profiles → term-lab → Keys → Key Mappings.- Choose Presets… → Natural Text Editing and confirm.
Check again with cat -v, type ⌥←,
⌘←, ⌘→:
^[b^A^E
Now ⌥← sends a Meta-B, ⌘← a ⌃A and ⌘→ a ⌃E.
Those are exactly the Emacs keys from Day 3. So the shell doesn’t have
to learn anything new.
Warning: A Dynamic Profile is rebuilt from the JSON file when it’s loaded. Changes made in the GUI are then lost. Carry them over into the JSON: select the profile, Other Actions… → Copy Profile as JSON, then copy the
Keyboard Mapblock into your file.
Save your progress? Sign up for free
Drill 5: Splits without a mouse
Open three panes in the lab window and jump between them:
| Step | Key | Result |
|---|---|---|
| 1 | ⌘D |
vertical split, new pane on the right |
| 2 | ⌘⇧D |
horizontal split, new pane bottom right |
| 3 | ⌘⌥← |
back to the left |
| 4 | ⌘] / ⌘[ |
next / previous split |
| 5 | ⌘⇧⏎ |
maximize the current split and back |
| 6 | ⌘W |
close the split |
Then tabs: ⌘T opens a tab with the same profile.
⌘1 to ⌘9 jump directly, ⌘⇧[ and
⌘⇧] cycle through them in order.
A pro trick for several servers: ⌘⌥I sends your input to
all splits in the tab (Broadcast Input). Pressing ⌘⌥I again
turns it off.
Tip: iTerm2 splits are good for quick glances. For anything that should survive an SSH drop or a restart of the app, use tmux (Day 8). Many senior engineers use only tabs in the terminal app and do splits exclusively in tmux.
Save your progress? Sign up for free
Drill 6: The hotkey window
A terminal that slides down with a single keypress, no matter which app is in front:
⌘,→ Keys → Hotkey → Create a Dedicated Hotkey Window…- Hotkey:
⌥Spaceor⌃^(⌃ plus the key to the left of 1). - Check Floating window and Animate showing and hiding.
- Under Profiles → Hotkey Window → General → Command,
choose Command and enter
/Users/du/term-lab/lab.
Test: switch to the browser, press the hotkey, type
git -C ~/term-lab/projekt log --oneline -1, press the
hotkey again.
Expected:
2e4e6aa chore: Config, Manifeste, Report
The window disappears, the browser is in front again. That way you look something up in three seconds without losing context.
Save your progress? Sign up for free
Drill 7: Shell integration and marks
iTerm2 can mark every prompt. Then you jump from command to command with keys and select an entire output at once. The integration is a small zsh script. We load it only in the practice zsh:
curl -fsSL https://iterm2.com/shell_integration/zsh \
-o ~/term-lab/config/iterm2_shell_integration.zsh
cat > ~/term-lab/config/zsh/iterm2.zsh <<'EOF'
# Only in iTerm2 and only with a real terminal (not in $(...) or pipes)
[[ $TERM_PROGRAM == iTerm.app && -t 1 ]] &&
source "$LAB/config/iterm2_shell_integration.zsh"
EOF
exec ~/term-lab/lab
echo "SI=$ITERM_SHELL_INTEGRATION_INSTALLED"Expected:
SI=Yes
The menu item iTerm2 → Install Shell Integration
would change your real ~/.zshrc. That’s why we go through
the lab configuration: .zshrc loads every file from
~/term-lab/config/zsh/. exec ~/term-lab/lab
replaces the running shell with a fresh one that rereads all files.
Now try it out:
ls -la ~/term-lab/projekt
git -C ~/term-lab/projekt log --oneline
wc -l ~/term-lab/projekt/logs/*.logPress ⌘⇧↑ twice: you jump to the prompt of
git log. ⌘⇧A selects the output of the last
command, ⌘C copies it. A triangle to the left of the prompt
shows each mark. If it’s red, the command ended with an error.
Save your progress? Sign up for free
Drill 8: Ghostty as an alternative
Ghostty is GPU-accelerated, starts very fast and is configured
through a single text file. Without a configuration file, Ghostty looks
in ~/.config/ghostty/config. We put the actual
configuration in the lab and only point to it:
mkdir -p ~/term-lab/config/ghostty
cat > ~/term-lab/config/ghostty/config <<EOF
# Lab configuration for Ghostty
font-family = JetBrainsMono Nerd Font Mono
font-size = 14
theme = Catppuccin Mocha
macos-option-as-alt = left
command = $HOME/term-lab/lab
working-directory = $HOME/term-lab/projekt
copy-on-select = clipboard
keybind = global:ctrl+grave_accent=toggle_quick_terminal
quick-terminal-position = top
EOFThen a single line in the (new) Ghostty configuration. The
? makes the file optional:
mkdir -p ~/.config/ghostty
echo 'config-file = ?~/term-lab/config/ghostty/config' >> ~/.config/ghostty/configWarning: If you’ve already set up Ghostty, look at the file first. The line goes at the end and overrides settings with the same name. Removing it is just as easy: delete the line.
Ghostty reloads with ⌘⇧,. Checking and looking things up
works via the CLI:
ghostty +show-config | grep -E 'font-family|option-as-alt|command'
ghostty +list-keybinds --default | grep -E 'new_split|goto_split' | head -4
ghostty +list-themes | head -3Expected (shortened, may differ depending on version):
font-family = JetBrainsMono Nerd Font Mono
macos-option-as-alt = left
command = /Users/du/term-lab/lab
keybind = super+d=new_split:right
keybind = super+shift+d=new_split:down
keybind = super+alt+left=goto_split:left
keybind = super+bracket_left=goto_split:previous
So the splits are already on the same keys as in iTerm2. With ⌃ plus
the key to the left of 1 (global; depending on the keyboard layout
⌃^ or ⌃`) the Quick Terminal slides in from
the top. For this, macOS asks once for Accessibility permission.
Because our start script sets ZDOTDIR itself, Ghostty
doesn’t load its shell integration automatically. Load it manually, as
described in the Ghostty docs:
cat > ~/term-lab/config/zsh/ghostty.zsh <<'EOF'
# Ghostty shell integration (prompt marks, working directory for new splits)
[[ -n $GHOSTTY_RESOURCES_DIR ]] &&
source "$GHOSTTY_RESOURCES_DIR/shell-integration/zsh/ghostty-integration"
EOFSave your progress? Sign up for free
Drill 9: Clipboard without a mouse
macOS ships two small helpers: pbcopy reads from stdin
into the clipboard, pbpaste prints it.
cd ~/term-lab/projekt
git log -1 --format=%H | pbcopy
pbpaste | cut -c1-7
grep ERROR logs/app.log | head -3 | pbcopy
pbpaste | wc -lExpected:
2e4e6aa
3
In tmux, Neovim and over SSH, pbcopy doesn’t always get
through. Then the OSC 52 escape sequence helps: the program sends the
text to the terminal app, and the app puts it on the clipboard. iTerm2
only allows this after Settings → General → Selection →
Applications in terminal may access clipboard. Ghostty allows
writing by default (clipboard-write = allow).
printf '\e]52;c;%s\a' "$(printf 'via OSC 52' | base64)"
pbpaste; echoExpected (if access is enabled):
via OSC 52
You’ll need this on Day 8 for tmux copy mode.
Save your progress? Sign up for free
Shortcut table
| Key | Effect | Mnemonic |
|---|---|---|
⌘D / ⌘⇧D |
split right / down | Divide |
⌘⌥←→↑↓ |
switch split | the arrow points there |
⌘] / ⌘[ |
next / previous split | bracket = in order |
⌘⇧⏎ |
maximize split (zoom) | make it big |
⌘T / ⌘W |
open / close tab | Tab, Wipe away |
⌘1…⌘9 |
select tab directly | number |
⌘O |
open profile (iTerm2) | Open |
⌘⌥I |
input to all splits (iTerm2) | Input to all |
⌘⇧↑ / ⌘⇧↓ |
to previous / next prompt mark | up to the command |
⌘⇧A |
select output of the last command | All output |
⌘F |
search the scrollback | Find |
⌘K |
clear the scrollback | Kill |
⌘, |
Settings | Mac standard |
| Hotkey | hotkey window / Quick Terminal | always there |
Checkpoint
Run the script in a window with the lab profile:
LAB=${LAB:-~/term-lab}
DP=~/Library/Application\ Support/iTerm2/DynamicProfiles/term-lab.json
ok() { local m=$1; shift; "$@" >/dev/null 2>&1 && echo "✔ $m" || echo "✘ $m"; }
ok "Lab-Shell aktiv" test "$ZDOTDIR" = "$LAB/zsh"
ok "Truecolor" test "$COLORTERM" = truecolor
ok "iTerm2 oder Ghostty" sh -c '[ "$TERM_PROGRAM" = iTerm.app ] ||
[ "$TERM_PROGRAM" = ghostty ]'
if [ "$TERM_PROGRAM" = iTerm.app ]; then
ok "Dynamic Profile gültig" jq -e '.Profiles[0].Name == "term-lab"' "$DP"
ok "Option = Esc+" jq -e '.Profiles[0]."Option Key Sends" == 2' "$DP"
ok "Shell-Integration" test "$ITERM_SHELL_INTEGRATION_INSTALLED" = Yes
fiExpected in iTerm2:
✔ Lab-Shell aktiv
✔ Truecolor
✔ iTerm2 oder Ghostty
✔ Dynamic Profile gültig
✔ Option = Esc+
✔ Shell-Integration
And the hands-on test no script can replace: type
echo eins zwei drei, then ⌥B three times. The
cursor must be in front of eins.
Challenge
Create a second Dynamic Profile term-lab-prod. It also
starts the lab shell, but has a dark red background and the badge
“PROD”. That way you see at a glance in which window you’re doing
dangerous things.
Hint: In the JSON, colors are a dictionary with
Red Component, Green Component and
Blue Component (values 0 to 1) under the key
Background Color.
Solution
D=~/Library/Application\ Support/iTerm2/DynamicProfiles
jq '.Profiles[0] += {
"Name": "term-lab-prod",
"Guid": "term-lab-prod-0001",
"Badge Text": "PROD",
"Background Color": {
"Red Component": 0.25, "Green Component": 0.02,
"Blue Component": 0.02, "Color Space": "sRGB"
}
}' "$D/term-lab.json" > "$D/term-lab-prod.json"
jq -r '.Profiles[] | "\(.Name) \(.["Badge Text"])"' "$D/term-lab-prod.json"Expected:
term-lab-prod PROD
The Guid must be unique, otherwise iTerm2 ignores the
second profile. On Day 14 you’ll do the same in the prompt: Kubernetes
context prod turns red.
Save your progress? Sign up for free
Enterprise Note
- Many company Macs only allow approved apps. iTerm2 is usually in the Self Service portal, Ghostty often not yet. Ask early.
- Dynamic Profiles can be distributed centrally, for example one profile per environment (dev, stage, prod) with its own color. iTerm2 reads them from the folder without anyone clicking.
- OSC 52 and “Applications may access clipboard” are convenient, but then every program in the terminal may write to your clipboard. On jump hosts with third-party code: decide deliberately.
- Secure Keyboard Entry (iTerm2 menu iTerm2 → Secure Keyboard Entry) prevents other apps from reading your keystrokes. Useful when typing passwords, but it can block tools like TextExpander.
- Screen sharing in meetings: keep a large profile with an 18 pt font
and a light theme ready.
⌘O, pick the profile, done.