Setting Up Starship Prompt in a DevContainer
Starship gives every shell the same fast, informative prompt from a single config — ideal for a devcontainer where the team may use different shells. This page installs Starship at image time, initializes it in each shell, and shares one starship.toml.
Prerequisites
You need a devcontainer and a shell to initialize Starship in.
- Starship installed in the image.
- An init line in the shell rc (zsh/fish/bash).
- A shared
starship.tomlconfig.
Step-by-Step Implementation
- Install Starship in the image.
RUN curl -fsSL https://starship.rs/install.sh | sh -s -- -y
- Initialize it in the shell (zsh shown).
grep -q 'starship init zsh' ~/.zshrc || echo 'eval "$(starship init zsh)"' >> ~/.zshrc
- Share one config.
# starship.toml (mounted or copied to ~/.config/starship.toml)
add_newline = false
[git_branch]
symbol = " "
- Verify the prompt renders in a new terminal.
Common Pitfalls
Starship issues are a missing init line or an unshared config.
| Symptom | Root Cause | Remediation |
|---|---|---|
| Prompt not showing | No init line in the rc | Add eval "$(starship init |
| Different prompt per developer | Config in personal dotfiles only | Share starship.toml in the config |
| Init line duplicated | Unguarded append | Guard with grep before appending |
| starship not found | Not installed in the image | Install it in the Dockerfile |
Conclusion
Starship gives one prompt for every shell from a single starship.toml. Install it at image time, add a guarded init line to the shell rc, and share the config so the whole team sees the same prompt — fast, informative, and shell-agnostic.
FAQ
Why Starship over a shell-specific prompt framework? Starship is cross-shell and compiled, so one config gives zsh, fish, and bash an identical, fast prompt. In a devcontainer where teammates may use different shells, that consistency and speed beats maintaining separate prompt frameworks per shell.
Where should the starship.toml live?
Share it through the config (copied or mounted to ~/.config/starship.toml) so everyone gets the same prompt, rather than leaving it in individual dotfiles. Personal tweaks can still layer on, but the shared config sets the team baseline.
How do I keep the init line from duplicating?
Guard the append (grep -q 'starship init' ~/.zshrc || echo … >> ~/.zshrc) since the bootstrap re-runs on each create. Or add the init line in the image's shell rc so it's baked in and never appended at runtime.
Related
- Up to Shell Environment Customization: zsh, fish, bash — the shell overview.
- Persisting zsh History Across Container Rebuilds — durable shell state alongside the prompt.
- Using GNU Stow for Dotfiles in a DevContainer — managing the config files.