# Terminal tools tutorial

A hands-on guide to everything set up by `install.sh` (see [README.md](README.md) for what gets installed and how). Work through it in order: each part builds on the previous one. Every section has the commands you will use daily and a short exercise.

Conventions: `$` is a shell prompt, `<name>` is a value you replace, and `Ctrl-X` means holding Control and pressing X.

## Contents

1. [Learning path](#learning-path)
2. [The shell: zsh, suggestions and completion](#1-the-shell-zsh-suggestions-and-completion)
3. [Navigating: zoxide, fzf, eza, yazi](#2-navigating-zoxide-fzf-eza-yazi)
4. [Reading and searching: bat, fd, ripgrep, jq](#3-reading-and-searching-bat-fd-ripgrep-jq)
5. [System insight: btop, duf, ncdu, dust, procs, fastfetch, hyperfine](#4-system-insight)
6. [Git: Delta and Lazygit](#5-git-delta-and-lazygit)
7. [Working in the terminal: Zellij and tldr](#6-working-in-the-terminal-zellij-and-tldr)
8. [The prompt: Starship](#7-the-prompt-starship)
9. [Per-project environments: direnv](#8-per-project-environments-direnv)
10. [Kubernetes](#9-kubernetes)
11. [Containers: Lazydocker](#10-containers-lazydocker)
12. [Cheat sheet](#cheat-sheet)

## Learning path

| Day | Focus | Goal |
| :--- | :--- | :--- |
| 1 | Parts 1 to 3 | Move around and find things without typing full paths |
| 2 | Parts 4 and 5 | Inspect the machine and use Git comfortably |
| 3 | Parts 6 to 8 | Multiple panes, a readable prompt, per-project variables |
| 4 | Parts 9 and 10 | Work on clusters and containers quickly and safely |

---

## 1. The shell: zsh, suggestions and completion

**What you get**
- **Autosuggestions**: as you type, a grey suggestion from your history appears.
- **Syntax highlighting**: valid commands turn green, unknown ones red.
- **fzf-tab**: pressing `Tab` opens an interactive menu with previews instead of a plain list.
- **Prefix history search**: type the start of a command and press Up or Down to cycle through matching entries.
- **Shared history**: 50,000 entries, shared between open terminals.
- **`AUTO_CD`**: typing a directory name enters it.

**Keys**

| Key | Action |
| :--- | :--- |
| `Tab` | Accept the grey suggestion if there is one, otherwise complete (through fzf-tab) |
| `Right`, `Ctrl-F`, `Ctrl-E`, `Ctrl-Space` | Accept the whole suggestion |
| `Alt-F`, `Ctrl-Right` | Accept the suggestion one word at a time |
| `Ctrl-Left` / `Ctrl-Right`, `Alt-Left` / `Alt-Right` | Move one word back / forward |
| `Ctrl-Delete` | Delete the next word |
| `Home` / `End` | Start / end of the line |
| `Up` / `Down` | Search history by what you already typed |
| `Ctrl-R` | Fuzzy search the whole history (fzf) |
| `Alt-P` (inside the Tab menu or `Ctrl-T`) | Toggle the preview |
| `<` and `>` (inside the Tab menu) | Switch completion group |

**Practice**
1. Type `git ch` and press `Tab`: pick `checkout` or `cherry-pick` from the menu.
2. Run `ls /etc`, then type `ls` and press Up: the previous `ls` commands appear first.
3. Type `cd ` and press `Tab`: directories are listed with a preview.

---

## 2. Navigating: zoxide, fzf, eza, yazi

### zoxide: `z`

It learns the directories you visit and jumps to them by partial name.

```bash
z projects        # jump to the most used directory matching "projects"
z ai conf         # several words narrow the match
zi                # interactive selection with fzf
z -               # previous directory
```

It needs a few visits to learn: use `cd` normally for a day and `z` becomes accurate.

### fzf

| Key | Action |
| :--- | :--- |
| `Ctrl-T` | Pick files or directories and paste the path on the command line (with a preview) |
| `Ctrl-R` | Fuzzy history search |
| `Alt-C` | Pick a directory and `cd` into it |

Inside any fzf list: type to filter, `Up`/`Down` to move, `Enter` to accept, `Esc` to cancel. Use it as a filter in pipelines too:

```bash
ls | fzf                     # choose one line
git branch | fzf             # choose a branch
vim $(fd -t f | fzf)         # choose a file to edit
```

### eza (`ls`, `ll`, `la`, `l`, `tree`)

| Command | Result |
| :--- | :--- |
| `ls` | Colorful listing with icons |
| `ll` | Long listing with hidden files and Git status per file |
| `la` | All files, including hidden |
| `tree` | Directory tree (`tree -L 2` limits the depth) |

### Yazi: `y`

A terminal file manager with previews. Start it with `y` (not `yazi`): when you quit, your shell moves to the directory you were browsing.

| Key | Action |
| :--- | :--- |
| `h` / `j` / `k` / `l` | Parent directory, down, up, enter or open |
| `Enter` | Open the file |
| `.` | Show or hide hidden files |
| `/` | Search in the current directory |
| `Space` | Select or deselect the item |
| `y`, `x`, `p` | Copy, cut, paste |
| `d`, `D` | Move to trash, delete permanently |
| `a` | Create a file (end the name with `/` for a directory) |
| `r` | Rename |
| `z`, `Z` | Jump with fzf, jump with zoxide |
| `F1` | Show all key bindings |
| `q` | Quit (and `cd` to the current directory) |

Image, PDF and video previews use chafa, poppler and ffmpeg, which the installer sets up.

**Practice**: run `y`, go into `~/zsh-setup`, press `.` to toggle hidden files, quit with `q`, then check that `pwd` shows where you left Yazi.

---

## 3. Reading and searching: bat, fd, ripgrep, jq

### bat (`cat`)

`cat` is an alias for `bat --paging=never`: syntax highlighting and line numbers without a pager.

```bash
cat install.sh              # highlighted output
bat -l yaml file            # force a language
bat -r 10:30 install.sh     # only lines 10 to 30
command cat file            # the original cat, e.g. for binary-safe piping
```

### fd

A faster, friendlier `find`. It ignores `.git` and files listed in `.gitignore` by default.

```bash
fd config                   # names containing "config"
fd -e yaml                  # by extension
fd -t d src                 # directories only
fd -H secret                # include hidden files
fd -e log -x gzip {}        # run a command on every match
```

### ripgrep: `rg`

A fast recursive `grep`.

```bash
rg "TODO"                   # search the current tree
rg -i "error" -g '*.log'    # case-insensitive, only matching file names
rg -n -C 2 "timeout"        # line numbers and 2 lines of context
rg -l "password"            # only file names
rg --files | rg yaml        # list files, then filter
```

### jq

Query and transform JSON.

```bash
curl -s https://api.github.com/repos/jqlang/jq | jq '.stargazers_count'
kubectl get pods -o json | jq -r '.items[].metadata.name'
kubectl get nodes -o json | jq '.items[] | {name: .metadata.name, kubelet: .status.nodeInfo.kubeletVersion}'
```

**Practice**: find every Markdown file under your home with `fd -e md`, then search them for a word with `rg word -g '*.md'`.

---

## 4. System insight

| Tool | Command | Use |
| :--- | :--- | :--- |
| btop | `top` (alias) | Live CPU, memory, disk, network and processes |
| duf | `df` (alias) | Readable table of mounted disks |
| ncdu | `ncdu /var` | Interactive disk usage browser |
| dust | `dust` | Visual disk usage tree |
| procs | `procs` | Modern process list |
| fastfetch | `ff` (alias) | System summary |
| hyperfine | `hyperfine '<cmd>'` | Benchmark commands |

**btop**: `Esc` opens the menu, `f` filters processes, `k` kills the selected one, `q` quits.

**ncdu**: arrows to move, `Enter` to open a directory, `d` to delete the selected item (it asks first), `q` to quit.

**dust**

```bash
dust                        # current directory, largest first
dust -d 2 -n 10 ~           # two levels deep, ten biggest entries
dust -r                     # reversed order
```

**procs**

```bash
procs                       # all processes with colors
procs firefox               # filter by keyword
procs --tree                # parent/child tree
procs --watch               # refresh continuously
procs --sortd cpu           # sort descending by CPU
```

**hyperfine**

```bash
hyperfine 'fd -e md' 'find . -name "*.md"'      # compare two commands
hyperfine --warmup 3 'rg TODO'                  # warm the cache first
hyperfine --runs 20 --export-markdown out.md 'zsh -ic exit'
```

`df` and `top` are aliases, so scripts still use the real commands; call them as `command df` if you need the original in an interactive session. `du` and `ps` are not aliased: use `dust` and `procs` by name.

**Practice**: run `hyperfine 'zsh -ic exit'` to measure your shell start-up time (about 0.07 s with the cached init).

---

## 5. Git: Delta and Lazygit

### Delta

Git uses Delta as its pager, so `git diff`, `git show` and `git log -p` already show syntax-highlighted diffs with line numbers.

| Key (inside the pager) | Action |
| :--- | :--- |
| `n` / `N` | Jump to the next or previous file (`navigate` is enabled) |
| `q` | Quit |

You can also diff any two files: `d file1 file2` (`d` is an alias for `delta`). Conflicts are written in the `zdiff3` style, which also shows the common ancestor between the two sides.

### Lazygit: `lg`

A terminal UI for Git. It has panels: Status, Files, Branches, Commits and Stash. Press `?` in any panel to see its keys.

| Key | Action |
| :--- | :--- |
| `1`..`5` or `Tab` | Switch panel |
| `Space` | Stage or unstage the selected file |
| `a` | Stage or unstage everything |
| `Enter` | Open the file's diff / go into the selected item |
| `c` | Commit |
| `P` / `p` | Push / pull |
| `n` | New branch (in the Branches panel) |
| `Space` (in Branches) | Check out the branch |
| `M` | Merge into the current branch |
| `z` | Undo the last action |
| `?` | Context help |
| `q` | Quit |

**Practice**: in a scratch repository, create two files, stage one with `Space`, commit it with `c`, then undo with `z`.

---

## 6. Working in the terminal: Zellij and tldr

### Zellij: `zj`

A multiplexer: several panes and tabs in one terminal, plus sessions that survive closing the window. The status bar at the bottom always shows the keys available in the current mode.

| Key | Mode | Then |
| :--- | :--- | :--- |
| `Ctrl-p` | Pane | `n` new pane, `x` close, arrows to move, `f` fullscreen |
| `Ctrl-t` | Tab | `n` new tab, `x` close, `r` rename, arrows to switch |
| `Ctrl-n` | Resize | arrows resize the focused pane |
| `Ctrl-s` | Scroll | `j`/`k` scroll, `e` open scrollback in the editor |
| `Ctrl-o` | Session | `d` detach (the session keeps running) |
| `Ctrl-g` | Lock | disables Zellij keys, useful for programs that use the same shortcuts |
| `Ctrl-q` | | Quit |

```bash
zj                          # start a session
zj ls                       # list sessions
zj attach <name>            # re-attach to a session
zr -- htop                  # run a command in a new pane
```

### tldr

Short, practical examples instead of long man pages (`tealdeer`).

```bash
tldr tar                    # common tar usage
tldr git rebase             # subcommands work too
tldr --update               # refresh the pages
```

**Practice**: start `zj`, split with `Ctrl-p` then `n`, run `top` in one pane and `tldr tar` in the other, detach with `Ctrl-o` then `d`, and come back with `zj attach`.

---

## 7. The prompt: Starship

The prompt shows, when relevant: operating system, current directory, Git branch and status, package version, language versions (Node, Python, Rust, Go), the Docker context, the **Kubernetes context and namespace**, and the duration of slow commands (over 2 s). The arrow turns red after a failed command.

**Kubernetes colors** (from the context name): red contains `prod`, yellow `stg`, green `dev`, blue anything else. Treat red as "be careful".

**Customizing**: edit `~/.config/starship.toml`.

```toml
# Hide the Kubernetes module outside Kubernetes-related folders
[kubernetes]
disabled = false
detect_files = ["Chart.yaml", "kustomization.yaml"]
```

```bash
starship explain            # what each visible module means right now
starship config             # open the config file in your editor
```

---

## 8. Per-project environments: direnv

direnv loads and unloads environment variables when you enter and leave a directory.

```bash
cd ~/project
echo 'export KUBECONFIG=$PWD/kubeconfig' > .envrc
direnv allow                # trust this file (required once, and after each edit)
cd ..                       # variables are unloaded automatically
direnv status               # what is loaded and why
```

direnv never runs an `.envrc` you have not allowed. Do not commit files with secrets in them; keep those out of the repository or encrypted.

---

## 9. Kubernetes

### Aliases at a glance

| Alias | Command |
| :--- | :--- |
| `k` | `kubectl` (colorized through `kubecolor` when installed) |
| `kg`, `kgp`, `kgpa`, `kgn`, `kgs`, `kgd`, `kgi`, `kgns` | `get`, pods, pods in all namespaces, nodes, services, deployments, ingresses, namespaces |
| `kd` | `describe` |
| `kl`, `klf` | `logs`, `logs -f` |
| `kex` | `exec -it` |
| `kpf` | `port-forward` |
| `kaf`, `kdf` | `apply -f`, `delete -f` |
| `kctx` | Show the current context |
| `kns [name]` | Show or set the namespace of the current context |
| `kx` / `kn` | `kubectx` / `kubens` |
| `ks` | `stern` |
| `h` | `helm` |
| `kconf` | `kubeconform -summary` |

`argocd` and `kustomize` have completion but no alias.

All of them complete with `Tab`, including resource names and namespaces.

### kubectl day to day

```bash
kgp                         # pods in the current namespace
kgpa                        # pods in every namespace
kgp -o wide                 # with node and IP
kd pod <name>               # events and details
kl <pod> -c <container>     # logs of one container
klf <pod> --tail 50         # follow logs
kex <pod> -- sh             # shell inside a pod
kpf svc/<name> 8080:80      # forward local 8080 to the service port 80
kg events --sort-by=.lastTimestamp
kubectl auth can-i delete pods
```

### kubectx and kubens: contexts and namespaces

```bash
kx                          # list contexts (current one highlighted)
kx <context>                # switch context
kx -                        # go back to the previous context
kx -c                       # print the current context
kn                          # list namespaces
kn <namespace>              # switch namespace
kn -                        # previous namespace
kns                         # print the namespace of the current context
```

Switching context changes shared state: every terminal and tool using the same kubeconfig changes with it. Check the prompt (red means production) before running anything that modifies resources. Prefer `kubectl --context <name>` for one-off commands on another cluster.

### k9s

A full-screen cluster browser. Start it with `k9s` (it uses the current context).

| Key | Action |
| :--- | :--- |
| `:pods`, `:deploy`, `:svc`, `:ns`, `:ctx` | Go to a resource type (`:ctx` switches context) |
| `/` | Filter the list (regex) |
| `Enter` | Drill into the selected item |
| `d` | Describe |
| `y` | View YAML |
| `e` | Edit |
| `l` | Logs |
| `s` | Shell into the container |
| `Ctrl-d` | Delete (asks for confirmation) |
| `0` | Show all namespaces |
| `?` | All key bindings |
| `Esc` / `:q` | Back / quit |

### stern: multi-pod logs (`ks`)

```bash
ks api -n prod                         # all pods whose name matches "api"
ks api --since 10m --tail 20           # recent lines only
ks -l app=api -c server                # by label and container
ks . -A --since 5m                     # every pod in every namespace
```

### kubecolor

Adds colors to `kubectl` output. It is on by default through the `kubectl` alias, so `k`, `kg`, `kd` and the others are colored. Bypass it with `command kubectl ...`.

### Helm (`h`)

```bash
h list -A                              # releases in all namespaces
h status <release> -n <ns>
h get values <release> -n <ns>
h template <release> <chart> -f values.yaml | kconf   # render and validate
h repo add <name> <url> && h repo update
```

### kubeconform (`kconf`)

Validates manifests against the Kubernetes schemas before you apply them.

```bash
kconf manifest.yaml
kconf -strict -ignore-missing-schemas dir/
kustomize build overlays/dev | kconf   # validate a kustomize build
```

### kustomize

Builds manifests from a base plus overlays. It completes with `Tab`.

```bash
kustomize build overlays/dev                 # render to stdout
kustomize build overlays/dev | kconf         # render and validate
kustomize build overlays/dev | k diff -f -   # compare with the live cluster
kustomize edit set image app=registry/app:1.2.3
```

### Argo CD

```bash
argocd login <server> --sso                  # authenticate (needed for app name completion)
argocd app list
argocd app get <app>                         # status, sync and health
argocd app diff <app>                        # what would change
argocd app sync <app>                        # apply (changes the cluster: check the context first)
argocd app history <app>
```

`argocd app <Tab>` completes subcommands, and app names once you are logged in.

### krew plugins

`~/.krew/bin` is on your `PATH`, so plugins run as `kubectl <plugin>`.

```bash
kubectl krew search
kubectl krew install <plugin>
kubectl get deploy <name> -o yaml | kubectl neat   # strip clutter from a manifest
```

`oidc-login` is the plugin behind OIDC authentication in your kubeconfig.

**Practice** (read-only): run `kctx`, then `kgns`, then `kgpa | head`. Open `k9s`, type `:ns`, filter with `/`, and quit with `:q`.

---

## 10. Containers: Lazydocker

`lzd` opens a terminal UI for Docker. With Podman, enable its Docker-compatible socket (`systemctl --user enable --now podman.socket`) and point `DOCKER_HOST` at it.

| Key | Action |
| :--- | :--- |
| `Tab` / arrows | Move between panels and items |
| `Enter` | Focus the selected item (logs, stats, config tabs) |
| `s` | Stop |
| `r` | Restart |
| `d` | Remove |
| `a` | Attach |
| `x` | Open the actions menu for the item |
| `/` | Filter |
| `q` | Quit |

**Practice**: start a container (`docker run -d --name demo nginx`), open `lzd`, find it in the Containers panel, read its logs, then remove it with `d`.

---

## Typing on an ISO Spanish keyboard

The key combinations in this guide were chosen to work on an ISO Spanish layout with a tenkeyless (80%) keyboard: there is no numeric keypad, and only letters, arrows, `Home`/`End`/`Delete` and `F1` are needed. Symbols that need `AltGr` (the right Alt key) on this layout:

| Symbol | Keys |
| :--- | :--- |
| `\|` | `AltGr` + `1` |
| `@` | `AltGr` + `2` |
| `#` | `AltGr` + `3` |
| `~` | `AltGr` + `4`, then `Space` (dead key on some setups) |
| `\` | `AltGr` + `º` |
| `[` `]` | `AltGr` + `` ` `` / `AltGr` + `+` |
| `{` `}` | `AltGr` + `´` / `AltGr` + `ç` |

Tips:
- `/` is `Shift` + `7`, `?` is `Shift` + `'`, `<` has its own key and `>` is `Shift` + `<`.
- Shortcuts use the left `Alt`; `AltGr` is a different key and types symbols instead.
- `Ctrl-/` is awkward here (it needs `Shift`), so the preview toggle is `Alt-P`.
- If `Ctrl-Space` does nothing, the desktop's input method may be capturing it; use `Right`, `Ctrl-F` or `Ctrl-E` to accept a suggestion.

## Cheat sheet

| I want to... | Do this |
| :--- | :--- |
| Jump to a known directory | `z <part-of-name>` |
| Find a file by name | `fd <name>` |
| Search file contents | `rg <text>` |
| Pick a file and paste its path | `Ctrl-T` |
| Search old commands | `Ctrl-R` |
| Browse files with previews | `y` |
| See disk usage | `dust` or `ncdu` |
| Find a process | `procs <name>` |
| Commit visually | `lg` |
| Split the terminal | `zj` then `Ctrl-p` `n` |
| Remember how a command works | `tldr <command>` |
| Check which cluster I am on | Look at the prompt, or `kctx` / `kns` |
| Switch cluster / namespace | `kx` / `kn` |
| Browse a cluster | `k9s` |
| Follow logs of many pods | `ks <pattern>` |
| Validate manifests | `kconf <file>` |
| Manage containers | `lzd` |
| Load project variables | `.envrc` then `direnv allow` |

## Where to go next

- Each tool has built-in help: `<tool> --help`, `tldr <tool>`, and `?` inside the TUIs (Lazygit, Lazydocker, k9s, Yazi).
- Put personal aliases and exports in `~/.zshrc.local`; the installer never overwrites it.
- If a prompt symbol shows as a box, select a Nerd Font in your terminal profile.
