Using the Starship Prompt in pipenv Virtual Environment on Mac OSX

While attending PyCon 2021 online, I learned about Starship prompt & was impressed. It isn’t all that impressive when you are just navigating the file system, but as soon as you enter a project directory…that is when it springs to life. There is some magic that looks at the files & suddenly will tell you some useful language information (python, nodeJS, etc.) as well as what git branch you are on. And it makes generous use of color to do that. For me, Starship just ticks a lot of the right boxes, not to mention is much, much easier to install & configure than my previous favorite prompt enhancer, powerline.

My only complaint that I had (note the verb tense) about Starship was that on my Mac, I lost it whenever I entered a pipenv shell. What helped me realize an easy solution was that I had installed Starship on my Ubuntu laptop & it didn’t exhibit this behavior.

So what’s the difference between the Mac & Ubuntu?

It seems to be where they get their bash settings from. Mac uses .bash_profile while Ubuntu uses .bashrc.

I created a simple .bashrc in my Mac user’s home directory with the following–and redundant–contents:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

# Supercharge -r with fzf (requires apt|brew install fzf)
[ -f ~/.fzf.bash ] && source ~/.fzf.bash

# Activate starship prompt
eval "$(starship init bash)"

I did find that my favorite command history fuzzy finder tool, fzf, wasn’t available in my virtual env either so it came along, & I added my aliases file as extra insurance. So if you go “reaching” for one of your favorite CLI commands & it’s doesn’t appear to be available in your pipenv virtual environment, just add it to your .bashrc.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.