Shell Integration
What it does
Section titled “What it does”One command sets up three features at once:
gitswitch install- Prompt segment — shows your active git identity in your shell prompt
- Identity nudge — suggests the right identity when you
cdinto a repo - Tab completion — completes
gitswitchcommands and profile names
Installation
Section titled “Installation”gitswitch installDetects your shell automatically and configures:
| Shell | Configuration |
|---|---|
| Starship | Adds [custom.gitswitch] block to ~/.config/starship.toml |
| oh-my-zsh | Creates plugin at ~/.oh-my-zsh/custom/plugins/gitswitch/ |
| Powerlevel10k | Prints manual step for ~/.p10k.zsh |
| Raw zsh/bash/fish | Appends directly to rc file |
Reload shell
Section titled “Reload shell”After running gitswitch install:
source ~/.zshrc # zshsource ~/.bashrc # bashsource ~/.config/fish/config.fish # fishOr simply open a new terminal.
Prompt segment
Section titled “Prompt segment”Shows your active git identity in your shell prompt.
Example
Section titled “Example”Before:
~/my-project $After (with gitswitch):
~/my-project [work: alice@company.com] $The segment only appears when you’re inside a git repo.
Format
Section titled “Format”The prompt shows:
- Profile nickname (e.g.,
work) - Email address (e.g.,
alice@company.com)
Customization
Section titled “Customization”With Starship
Section titled “With Starship”Edit ~/.config/starship.toml:
[custom.gitswitch]command = "gitswitch current --short"when = "git rev-parse --git-dir 2>/dev/null"symbol = "🔑 "format = "[$symbol$output]($style) "style = "bold 208" # OrangeChange the symbol, color, or format as desired.
With oh-my-zsh
Section titled “With oh-my-zsh”Edit ~/.oh-my-zsh/custom/plugins/gitswitch/gitswitch.plugin.zsh:
# Customize the prompt functionGITSWITCH_PROMPT_SYMBOL="🔑 "GITSWITCH_PROMPT_COLOR="%F{208}"With raw zsh/bash/fish
Section titled “With raw zsh/bash/fish”Edit your rc file directly:
# In ~/.zshrc or ~/.bashrcPROMPT='%F{208}[$(gitswitch current)]%f $ ' # ZshPS1='\[$(gitswitch current)\] $ ' # BashIdentity nudge
Section titled “Identity nudge”When you cd into a repo, gitswitch suggests the identity you usually use there.
Example
Section titled “Example”$ cd ~/work-projectgitswitch: this repo usually uses work <alice@company.com> — switch? [y/N]Press y to switch, or just hit enter to skip. Non-blocking.
How it learns
Section titled “How it learns”Nudges appear after you’ve used an identity in a repo:
- ≥3 times with ≥60% consistency
gitswitch records each cd into a repo and remembers which identity was active.
Disable nudges
Section titled “Disable nudges”If you find nudges annoying:
# Edit ~/.config/gitswitch/config.json{ "nudge_on_cd": false}Or disable per-shell:
oh-my-zsh:
# Comment out or remove the nudge call in the pluginStarship:
# Remove the nudge hook from starship.tomlTab completion
Section titled “Tab completion”Completes gitswitch commands and profile names.
$ gitswitch <TAB>add current help install list pin remove switch version
$ gitswitch w<TAB>work # (if you have a 'work' profile)Supported shells
Section titled “Supported shells”- zsh — automatic if installed
- bash — automatic if installed
- fish — automatic if installed
Troubleshooting
Section titled “Troubleshooting”Prompt segment not showing
Section titled “Prompt segment not showing”Check:
- Is
gitswitch installcomplete? - Did you reload your shell?
- Are you in a git repo?
# Test manuallygitswitch current
# Should show your active profileNudges not appearing
Section titled “Nudges not appearing”Check:
- Is shell integration installed? (
gitswitch install) - Are you in a git repo?
- Have you used an identity in this repo ≥3 times?
# Check historycat ~/.config/gitswitch/history.jsonStarship doesn’t show the segment
Section titled “Starship doesn’t show the segment”Starship might not have loaded the config. Reload:
# Force starship to reloadpkill starship
# Or restart your terminalCompletion not working
Section titled “Completion not working”Ensure you’re using a supported shell version:
bash --version # Bash 4+zsh --version # Zsh 5+fish --version # Fish 3+If upgrading doesn’t help, reinstall:
gitswitch installsource ~/.zshrc # or .bashrcAdvanced customization
Section titled “Advanced customization”Custom prompt function
Section titled “Custom prompt function”You can write your own prompt function:
# In ~/.zshrcgitswitch_prompt() { local current=$(gitswitch current) if [ -n "$current" ]; then echo "[$current]" fi}
PROMPT='$(gitswitch_prompt) $ 'Conditional nudge
Section titled “Conditional nudge”Only nudge in certain directories:
# In shell pluginif [[ $PWD == *"work"* ]]; then gitswitch nudge # (if this command existed)fi