Say Goodbye to "base" - Displaying Your Virtual Environment in VSCode Terminal with Starship
Tired of staring at "base" every time you open a new terminal in VSCode? Want to instantly know which virtual environment you're working in? Then you need Starship, the blazing fast, customizable prompt for your shell!
The Problem:
VSCode's built-in terminal often displays a generic "base" prompt, making it difficult to quickly identify the active virtual environment, especially when working on multiple projects. This can lead to accidental code execution in the wrong environment, causing unexpected bugs and frustration.
The Solution:
Starship, a modern, highly customizable prompt, offers a seamless solution to this common problem. With just a few simple configurations, Starship can dynamically display your active virtual environment directly in your terminal.
Getting Started with Starship
-
Install Starship:
curl -fsSL https://starship.rs/install.sh | sh
-
Configure Starship:
Open your shell's configuration file (e.g.,
~/.zshrc
for Zsh) and add the following lines:eval "$(starship init zsh)" export STARSHIP_CONFIG="~/.config/starship/starship.toml"
-
Customize Your Prompt:
Create a new file at
~/.config/starship/starship.toml
(or edit the existing file if you already have a custom configuration). Add the following section:[virtualenv] style = "bold blue" symbol = "🐍" format = "{name}"
Explanation:
- style: Sets the color and boldness of the virtual environment name (bold blue in this case).
- symbol: Adds a snake emoji (🐍) to visually indicate the virtual environment.
- format: Displays only the name of the virtual environment.
-
Restart your terminal:
Close and reopen your VSCode terminal to see the changes.
Example:
Now, whenever you activate a virtual environment, your terminal prompt will dynamically display the name of the active environment, for example:
(my-project) 💻
Advantages of Starship:
- Dynamic Environment Display: Starship automatically detects and displays the active virtual environment without manual intervention.
- Customization: Customize the prompt to your liking with different colors, symbols, and formats.
- Performance: Starship is optimized for speed and efficiency, delivering a responsive terminal experience.
- Extensive Features: Beyond virtual environments, Starship offers a range of features like Git status, time, battery level, and more.
Conclusion:
With Starship, you can bid farewell to the ambiguity of "base" in your VSCode terminal. Experience the power of a dynamic and visually informative prompt that enhances your development workflow. Embrace clarity and productivity with Starship!
Resources: