Shell Integration
Shell integration provides automatic environment activation and command completion.
Setting Up Shell Integration
bash
# Add to ~/.bashrc
eval "$(vx shell init bash)"zsh
# Add to ~/.zshrc
eval "$(vx shell init zsh)"fish
# Add to ~/.config/fish/config.fish
vx shell init fish | sourcepowershell
# Add to $PROFILE
Invoke-Expression (& vx shell init powershell | Out-String)What Shell Integration Provides
1. Automatic PATH Setup
Your PATH is configured to find vx-managed tools:
bash
# Without shell integration
/usr/bin/node # System node
# With shell integration
~/.local/share/vx/envs/default/node # vx-managed node2. Directory-Based Environment Switching
When you cd into a directory with vx.toml, the environment automatically activates:
bash
cd my-project/ # Activates project environment
cd ~ # Returns to default environment3. Command Completion
Tab completion for vx commands and options:
bash
vx ins<TAB> # Completes to "vx install"
vx install no<TAB> # Completes to "vx install node"Shell Completions
Generate completion scripts separately:
bash
vx shell completions bash > ~/.local/share/bash-completion/completions/vxzsh
vx shell completions zsh > ~/.zfunc/_vxfish
vx shell completions fish > ~/.config/fish/completions/vx.fishpowershell
vx shell completions powershell > ~\Documents\PowerShell\Completions\vx.ps1Environment Indicators
With shell integration, your prompt can show the active environment:
bash
PS1='$([ -n "$VX_ENV" ] && echo "[$VX_ENV] ")'"$PS1"zsh
PROMPT='%F{cyan}${VX_ENV:+[$VX_ENV] }%f'"$PROMPT"fish
function fish_prompt
if set -q VX_ENV
echo -n "[$VX_ENV] "
end
# ... rest of prompt
endpowershell
function prompt {
if ($env:VX_ENV) {
Write-Host "[$env:VX_ENV] " -NoNewline -ForegroundColor Cyan
}
# ... rest of prompt
}Manual Environment Activation
If you prefer manual control:
bash
# Activate specific environment
eval "$(vx env activate my-env)"
# Deactivate (restore default)
eval "$(vx env activate default)"Troubleshooting
Shell Integration Not Working
Verify installation:
bashvx shell init bash # Should output shell scriptCheck if sourced correctly:
bashsource ~/.bashrc echo $PATH | grep vx # Should show vx pathsRestart your terminal
Completions Not Working
Verify completion script exists:
bashls ~/.local/share/bash-completion/completions/vxFor Zsh, ensure
compinitis called:zshautoload -Uz compinit && compinit
Slow Shell Startup
If shell startup is slow:
Use lazy loading:
bash# Bash - lazy load vx vx() { unset -f vx eval "$(command vx shell init bash)" vx "$@" }Cache the init script:
bash# Generate once vx shell init bash > ~/.vx-init.sh # Source cached version source ~/.vx-init.sh
Advanced Configuration
Disable Auto-Switching
If you don't want automatic environment switching:
bash
export VX_AUTO_SWITCH=false
eval "$(vx shell init bash)"Custom Hook
Add custom behavior when environment changes:
bash
# Bash
vx_env_changed() {
echo "Switched to environment: $VX_ENV"
# Custom logic here
}Next Steps
- CLI Reference - Shell command reference
- Environment Management - Managing environments