Prompt Customization
Customize your shell prompt to display the active DVS application.
Overviewβ
When you set the DVS_ACTIVE_APP environment variable, DVS automatically adds an indicator to your shell prompt showing the active app name: (dvs:app-name).
This indicator is compatible with most shell configurations and custom prompts (OhMyZsh, Starship, etc.).
Automatic Prompt Integrationβ
The prompt indicator is automatically added by the DVS wrapper script (~/.config/devspaces/helpers/wrapper.sh) when:
- The
DVS_ACTIVE_APPenvironment variable is set to a valid app name - The
DVS_PROMPT_DISABLEenvironment variable is not set to1
The integration uses shell hooks to avoid breaking custom prompts:
- Bash: Uses
PROMPT_COMMANDhook - Zsh: Uses
precmdhook viaadd-zsh-hook - Fish: Wraps the
fish_promptfunction
Disabling the Prompt Indicatorβ
To disable the automatic prompt indicator, set the DVS_PROMPT_DISABLE environment variable:
export DVS_PROMPT_DISABLE=1
To re-enable it:
unset DVS_PROMPT_DISABLE
You can also add this to your shell configuration file to make it permanent:
# In ~/.bashrc, ~/.zshrc, or ~/.config/fish/config.fish
export DVS_PROMPT_DISABLE=1
Custom Prompt Integrationβ
Starshipβ
For a more integrated experience with Starship, you can add a custom module to your ~/.config/starship.toml:
[custom.dvs]
command = "echo $DVS_ACTIVE_APP"
when = "test -n \"$DVS_ACTIVE_APP\""
format = "[$symbol($output )]($style)"
symbol = "π
"
style = "bold green"
This will display the active app name with a custom symbol and styling that matches your Starship theme.
OhMyZshβ
For OhMyZsh themes, you can customize the prompt by adding to your ~/.zshrc:
# DVS app indicator for OhMyZsh
_dvs_prompt_app() {
if [ -n "$DVS_ACTIVE_APP" ]; then
echo "%F{green}(dvs:$DVS_ACTIVE_APP)%f "
fi
}
# Add to your theme's prompt (example for robbyrussell theme)
# PROMPT='$(_dvs_prompt_app)'$PROMPT
Or integrate it into a custom theme function that's called by your theme.
Other Custom Promptsβ
For other custom prompt systems, you need to read the active app dynamically each time the prompt is displayed. Here are examples for different shells:
Bash:
# Function to get active app (called before each prompt)
_dvs_get_active_app() {
if [ -n "$DVS_ACTIVE_APP" ]; then
echo "(dvs:$DVS_ACTIVE_APP) "
fi
}
# Add to PROMPT_COMMAND to update prompt dynamically
PROMPT_COMMAND='DVS_APP_INDICATOR=$(_dvs_get_active_app); '"$PROMPT_COMMAND"
# Use in your prompt
PS1='$DVS_APP_INDICATOR'"$PS1"
Zsh:
# Function to get active app (called before each prompt)
_dvs_get_active_app() {
if [ -n "$DVS_ACTIVE_APP" ]; then
echo "%F{green}(dvs:$DVS_ACTIVE_APP)%f "
fi
}
# Add to precmd hook
autoload -Uz add-zsh-hook
add-zsh-hook precmd _dvs_update_prompt
_dvs_update_prompt() {
DVS_APP_INDICATOR=$(_dvs_get_active_app)
}
# Use in your prompt
PROMPT='$DVS_APP_INDICATOR'"$PROMPT"
Fish:
# Function to get active app
function _dvs_get_active_app
if test -n "$DVS_ACTIVE_APP"
echo -n "(dvs:$DVS_ACTIVE_APP) "
end
end
# Use in fish_prompt
function fish_prompt
echo -n (_dvs_get_active_app)
# ... rest of your prompt
end
Important: The DVS_ACTIVE_APP environment variable is read directly from your shell environment. The indicator updates immediately when you set or unset the variable.
Environment Variableβ
DVS_PROMPT_DISABLEβ
Controls whether the automatic prompt indicator is displayed.
- Default:
0(prompt indicator enabled) - Values:
0or unset: Prompt indicator is shown when an app is active1: Prompt indicator is disabled
Example:
# Disable prompt indicator
export DVS_PROMPT_DISABLE=1
# Re-enable prompt indicator
unset DVS_PROMPT_DISABLE
# or
export DVS_PROMPT_DISABLE=0
Updating the Promptβ
After setting or unsetting DVS_ACTIVE_APP, the prompt indicator updates automatically. However, if you don't see the change:
- Restart your shell (open a new terminal)
- Or reload the wrapper script:
source ~/.config/devspaces/helpers/wrapper.sh
See Alsoβ
- Active Application - Control active application via environment variable