0

I'm using MacOS and bash.

I'm using pipenv for virtual environments and I really want to make the look of my virtual shell match the look of my standard shell.

When I'm outside of pipenv, I set my .bash_profile so I could have the time, a green command prompt that shows the full path of my working directory and, if that directory has a git repo, it shows my current branch at the end.

I've searched for the correct file to edit to get the same look for each new pipenv shell, but I'm not having any luck finding the right file to copy my profile preferences to.

I'm wondering how I can set it up with my standard PS1 terminal appearance (colors and current git branch, etc).

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Chris B.
  • 11
  • 2
  • 3

2 Answers2

0

pipenv-FAQ

Look at the shell does not show the virtualenv’s name in prompt:

This is intentional. You can do it yourself with either shell plugins, or clever PS1 configuration. If you really want it back, use

And for the "shell plugins"

You need to look not for "pipenv+bash" but for virtualenv+bash prompt solutions, such as:

How do I change the default virtualenv prompt?

It's hard for me to recommend "Which way is the best?"

(I'm using zsh myself)

Alex Yu
  • 3,412
  • 1
  • 25
  • 38
0

I've searched for the correct file to edit to get the same look for each new pipenv shell, but I'm not having any luck finding the right file to copy my profile preferences to.

For bash, you can create and modify ~/.bashrc.

The pipenv shell command is a wrapper for virtualenv, which checks for a ~/.bashrc file when it activates a virtual environment for a bash shell. Anything in the ~/.bashrc file gets used in the spawned shell, including prompts, aliases, and other things you customized in your shell.

$ cat ~/.bashrc
cat: /Users/gino/.bashrc: No such file or directory

$ pipenv shell
Launching subshell in virtual environment…
bash-5.0$  . /Users/gino/.venvs/test-oiEjhH94/bin/activate
(test) bash-5.0$ ll
bash: ll: command not found
(test) bash-5.0$ exit

$ vim ~/.bashrc
$ cat ~/.bashrc
PS1='\[\e[1;33m\]\u@\W\$\[\e[0m\] '
alias ll="ls -Flh"

$ pipenv shell
Launching subshell in virtual environment…
gino@test$  . /Users/gino.mempin/.venvs/test-oiEjhH94/bin/activate
(test) gino@test$ 
(test) gino@test$ type ll
ll is aliased to `ls -Flh'

What you can do is to have a ~/.bash_prompt file where you set all your prompt configs (PS1) and a ~/.bash_aliases file where you set all your aliases. Then, source them both in the ~/.bash_profile (for the standard shell) and in the ~/.bashrc (for the pipenv shell).

~/.bash_prompt

# Format the prompt
# Shows up as:
#   machine-name@current-working-directory$
PS1='\[\e[1;33m\]\u@\W\$\[\e[0m\] '

# other prompt configs

~/.bash_aliases

alias ll="ls -FlhpG"

# other aliases

~/.bash_profile

# For "main" shell (i.e. Terminal, VS Code terminal)

. ~/.bash_prompt
. ~/.bash_aliases

~/.bashrc

# For `pipenv shell`

. ~/.bash_prompt
. ~/.bash_aliases

A better solution would be to tell pipenv shell or virtualenv to reuse the configs in the ~/.bash_profile, but I haven't got that successfully to work (Terminal, pipenv, VS Code).


  • macOS 10.15
  • bash 5.0 (installed via Homebrew)
  • pipenv 2020.8.13
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135