# Zsh terminal environment

`install.sh` sets up a modern zsh environment on a fresh machine: Starship prompt, fzf and fzf-tab, zoxide, eza, bat, Yazi, Zellij, Lazygit, Git with Delta, direnv, tealdeer, dust, procs, hyperfine, Lazydocker, and the Kubernetes CLI tools (kubectl, kubectx, kubens, kubeconform) with aliases and completion.

Supported: Fedora/RHEL, Debian/Ubuntu (and derivatives), macOS (Homebrew or Zerobrew), on x86_64 and aarch64.

For a hands-on guide to every tool, see [TUTORIAL.md](TUTORIAL.md).

## What gets installed

### Installed by the script

| Tool | Purpose | How it is installed |
| :--- | :--- | :--- |
| zsh | Shell, set as login shell on Linux | Package manager |
| zsh-autosuggestions, zsh-syntax-highlighting | Fish-like suggestions and command highlighting | Package manager |
| fzf-tab | Interactive Tab completion menu with previews | `git clone` into `~/.fzf-tab` |
| fzf | Fuzzy finder (`Ctrl-T`, `Ctrl-R`, `Alt-C`) | Package manager |
| Starship | Prompt (Git, language versions, Kubernetes context) | Release binary, SHA-256 checked (brew on macOS) |
| zoxide | Smart `cd` (`z`) | Package manager |
| eza, bat, fd, ripgrep, jq | Modern `ls`, `cat`, `find`, `grep` and JSON processor | Package manager |
| btop, duf, ncdu, dust, procs, fastfetch | Monitor, disks, disk usage, processes, system info | Package manager |
| hyperfine | Command benchmarking | Package manager |
| tealdeer (`tldr`) | Short command cheat sheets | Package manager, pages downloaded at the end |
| direnv | Per-directory environment variables | Package manager |
| git, git-delta | Git and its diff pager | Package manager |
| Lazygit, Lazydocker | Git and container terminal UIs | Release binary, SHA-256 checked |
| Yazi (+ chafa, poppler, 7zip, ffmpeg) | File manager and its preview helpers | Release binary, no checksum published |
| Zellij | Terminal multiplexer | Release binary, SHA-256 checked |
| kubectl, kubectx, kubens | Kubernetes CLI and context/namespace switchers | Release binaries, SHA-256 checked, with zsh completions |
| kubeconform | Kubernetes manifest validation | Release binary, SHA-256 checked |
| JetBrainsMono Nerd Font | Icons and prompt symbols | Downloaded to `~/.local/share/fonts` |

On Debian/Ubuntu, `fd` and `bat` are exposed through `/usr/local/bin` symlinks to `fdfind` and `batcat`.

### Used when present (not installed by the script)

The generated `~/.zshrc` adds aliases and completion for these only if they already exist: `kubecolor`, `k9s`, `stern`, `helm`, `argocd`, `kustomize`, and kubectl plugins installed with krew (`~/.krew/bin` is added to the `PATH`).

### Files written

| File | Content |
| :--- | :--- |
| `~/.zshrc` | Shell configuration, aliases, completion, plugins |
| `~/.config/starship.toml` | Prompt layout, Kubernetes module and colors |
| `~/.config/yazi/yazi.toml` | File manager settings |
| `~/.gitconfig` | Delta as pager, `zdiff3` conflict style (via `git config --global`) |
| `~/.cache/zsh/` | Cached init output (created on first shell start) |

## Fresh installation: steps

1. **Prerequisites**
   - `curl` and a user with `sudo` (or run as root).
   - Network access to GitHub, `dl.k8s.io` and `raw.githubusercontent.com`.
2. **Preview the changes (optional, recommended)**
   ```bash
   DRY_RUN=1 ./install.sh
   ```
   Prints what would be installed or written; nothing is changed.
3. **Run the installer**
   ```bash
   chmod +x install.sh
   ./install.sh
   ```
4. **Select a Nerd Font** (for example *JetBrainsMono Nerd Font*) in the terminal profile. The installer downloads it, but the terminal must be told to use it.
5. **Start the new shell**
   ```bash
   exec zsh
   ```
   Log out and back in so the new default shell applies to every terminal.
6. **Verify**
   ```bash
   echo $SHELL                 # path to zsh
   alias k kx kn               # k=kubectl, kx=kubectx, kn=kubens
   kubectl version --client
   kubectx -h && kubens -h
   tldr tar                    # tealdeer pages (downloaded by the installer)
   ```

## What the installer does

| Step | Action |
| :--- | :--- |
| 1 | Installs packages with the system package manager (zsh, plugins, bat, eza, btop, duf, ncdu, fd, ripgrep, fzf, zoxide, git-delta, fastfetch, direnv, tealdeer, dust, procs, hyperfine, ffmpeg, and others). Installs only what is missing and retries one by one if a batch fails. |
| 1 | Linux only: installs Starship, Yazi, Zellij, Lazygit, Lazydocker, kubectl, kubeconform, kubectx and kubens from their releases into `/usr/local/bin`, with zsh completions in `/usr/local/share/zsh/site-functions`. Each download is checked against the published SHA-256, except Yazi, which publishes none. |
| 2 | Clones (or updates) fzf-tab into `~/.fzf-tab`. |
| 3 | Installs JetBrainsMono Nerd Font into `~/.local/share/fonts` (Linux) or via brew (macOS). |
| 4 | Linux only: makes zsh the login shell. |
| 5 | Configures Git to use Delta as pager and diff filter (`~/.gitconfig`). |
| 6 | Writes `~/.config/starship.toml`. |
| 7 | Writes `~/.config/yazi/yazi.toml`. |
| 8 | Writes `~/.zshrc`. |
| 9 | Downloads the tldr pages (`tldr --update`). |

Existing `~/.gitconfig`, `starship.toml`, `yazi.toml` and `.zshrc` are copied to `<file>.backup.<timestamp>` before being overwritten.

## Options

| Variable | Effect |
| :--- | :--- |
| `DRY_RUN=1` | Only print the actions. |
| `SKIP_GIT_CONFIG=1` | Do not touch the Git configuration. |
| `SKIP_FONT=1` | Do not install a Nerd Font. |
| `YAZI_VERSION`, `ZELLIJ_VERSION`, `LAZYGIT_VERSION`, `LAZYDOCKER_VERSION`, `STARSHIP_VERSION`, `KUBECTL_VERSION`, `KUBECTX_VERSION`, `KUBECONFORM_VERSION` | Pin a release tag instead of the latest one (for example `KUBECTL_VERSION=v1.37.1`). |

## Kubernetes aliases

Defined only when the corresponding command exists.

| Alias | Command |
| :--- | :--- |
| `k` | `kubectl` |
| `kg`, `kgp`, `kgpa`, `kgn`, `kgs`, `kgd`, `kgi`, `kgns` | `kubectl get` / pods / pods `-A` / nodes / svc / deploy / ingress / namespaces |
| `kd` | `kubectl describe` |
| `kl`, `klf` | `kubectl logs` / `logs -f` |
| `kex` | `kubectl exec -it` |
| `kpf` | `kubectl port-forward` |
| `kaf`, `kdf` | `kubectl apply -f` / `delete -f` |
| `kctx` | `kubectl config current-context` |
| `kns [name]` | show or set the namespace of the current context |
| `kx` | `kubectx` |
| `kn` | `kubens` |
| `ks` | `stern` |
| `h` | `helm` |
| `kconf` | `kubeconform -summary` |
| `lzd` | `lazydocker` |

All aliases have tab completion, and `k9s`, `stern`, `helm`, `argocd` and `kustomize` complete as well. When `kubecolor` is installed, `kubectl` is aliased to it, so every `k*` alias gets colorized output (the `kns` function bypasses it). kubectl plugins installed with krew work because `~/.krew/bin` is added to the `PATH`.

## Shell behavior

- `AUTO_CD`: typing a directory name enters it.
- History keeps 50,000 entries, shared between sessions.
- `EDITOR` defaults to `nano` and `VISUAL` to `$EDITOR`; override them in `~/.zshrc.local`.
- `direnv` is hooked into the shell: put variables in a project's `.envrc` and trust it with `direnv allow`.

## Prompt

Starship shows the active Kubernetes context and namespace (for example `󱃾 prod-mad (default)`). The context is colored by name: red when it contains `prod`, yellow for `stg`, green for `dev`, blue otherwise. Edit `[[kubernetes.contexts]]` in `~/.config/starship.toml` to change the patterns.

## Keyboard

Key bindings are chosen for an ISO Spanish layout on a tenkeyless keyboard (no numeric keypad). The fzf preview toggle is `Alt-P` instead of `Ctrl-/`, which needs `Shift` on this layout. `Home`, `End`, `Delete`, `Ctrl`/`Alt` + arrows and `Ctrl-Delete` are bound for the common terminal variants. The `AltGr` combinations for `|`, `@`, `#`, `~`, `\`, `[ ]` and `{ }` are listed in [TUTORIAL.md](TUTORIAL.md#typing-on-an-iso-spanish-keyboard).

## Customization

- Put machine-specific aliases and exports in `~/.zshrc.local`; it is sourced last and is never overwritten by the installer.
- Re-running `install.sh` regenerates `~/.zshrc`, so changes made directly in it are lost (recoverable from the backup).

## Notes and troubleshooting

- The completion dump is rebuilt at most once a day. After installing a new completion, run `rm ~/.zcompdump && exec zsh`.
- Init output of fzf, zoxide, starship and kubectl completion is cached in `~/.cache/zsh`; delete that directory to force a rebuild.
- Icons or prompt symbols render as boxes: the terminal is not using a Nerd Font.
- `chsh` fails: run `chsh -s "$(command -v zsh)"` manually, then log out and in.
- A checksum error aborts the installation on purpose. Retry, or pin a version with the variables above.
- `kns` changes the namespace stored in the kubeconfig; check the active context first with `kctx`.
