# Guide to Installing and Setting Up Krew and Starship Prompt

### This playbook establishes a modern Kubernetes CLI workflow. You'll install Krew and the `ctx/ns` plugins for quick, hassle-free context and namespace switching, and configure the Starship prompt to display `⎈ <context> <namespace>` directly in Zsh. An optional fzf step adds fuzzy selection for interactive pickers. All steps are aware of the operating system and architecture (Linux/macOS, Intel/ARM) and are safe to run multiple times.

### **0.Prerequisites**

Ensure `kubectl` is installed and in your `PATH`.

Install `ohmyzsh` in your terminal

### **1\. Install Krew and the ctx/ns plugins:**

```bash
( set -euxo pipefail
  cd "$(mktemp -d)"
  OS="$(uname | tr '[:upper:]' '[:lower:]')"
  ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/armv[0-9]*/arm/' -e 's/aarch64$/arm64/')"
  KREW="krew-${OS}_${ARCH}"
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz"
  tar zxvf "${KREW}.tar.gz"
  ./"${KREW}" install krew
)
```

Add Krew to `PATH` (Zsh):

```bash
grep -q '\.krew.*/bin' ~/.zshrc || echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
```

Install plugins:

```bash
kubectl krew install ctx ns
```

Then install fzf:

```bash
sudo apt update && sudo apt install -y fzf
```

Usege:

```bash
kubectl ctx                 # list & interactively switch contexts
kubectl ctx <context>       # switch directly
kubectl ctx -               # toggle to previous context
kubectl ns                  # list & switch namespaces
kubectl ns <namespace>      # switch directly        
```

(Optional short aliases in ~/.zshrc: `alias kctx='kubectl ctx` and `alias kns='kubectl ns`)

### 2.Install and enable Starship

Install Starship:

```bash
curl -sS https://starship.rs/install.sh | sh
```

Enable Starship for Zsh (must be the last line in `~/.zshrc`):

```bash
grep -q 'starship init zsh' ~/.zshrc || echo 'eval "$(starship init zsh)"' >> ~/.zshrc
source ~/.zshrc
```

### 3.Configure Starship to show Kubernetes context/namespace

Create config file ~/.config/starship.toml:

```bash
mkdir -p ~/.config
cat > ~/.config/starship.toml <<'TOML'
format = "$kubernetes$directory$git_branch$git_status$python$character"

[kubernetes]
disabled = false
symbol = "⎈ "
style = "bold blue"
format = '[$symbol$context( \($namespace\))]($style) '

detect_files = []
detect_extensions = []
detect_folders = []

contexts = [
  { context_pattern = "kubernetes-super-admin@cluster.local", context_alias = "DemoCluster" },
  { context_pattern = "kind-kind", context_alias = "kind" }
]

[directory]
truncation_length = 3

[git_branch]
format = " on [$symbol$branch]($style) "

[git_status]
format = "([$all_status]($style)) "

[python]
disabled = true

[character]
success_symbol = " ➜ "     
error_symbol   = " ✗ "         
vimcmd_symbol  = " ❮ "     
```

You should see something like:

```bash
⎈ DemoCluster (default) ~  ➜
```
