Open jdkram opened 6 years ago
+1 on this, speaking as someone who only just installed fish shell (and fisher, and bobthefish).
The way I did it was similar, but instead of changing the output of the if [ "$VIRTUAL_ENV" ]
condition, I preceded that line with a tweaked version of the first line in the function:
[ "$theme_display_virtualenv" = 'glyph' -o -z "$VIRTUAL_ENV" -a -z "$CONDA_DEFAULT_ENV" ]; and return
This causes an early return from the function after the glyph has been printed, but before the virtualenv/pipenv name is printed. Instead of adding a separate variable for this, the new line adds a third option to the theme_display_virtualenv
variable: glyph
. (It works because the rest of the prompt code never checks for yes
, only no
.)
Being a newbie, I'm not sure how well or badly this idea fits with the overall bobthefish config philosophy, though there are a couple of other theme_*
variables with extra options alongside yes
and no
: theme_display_user
also has ssh
, and theme_newline_cursor
also has clean
.
Are Pipenv virtualenv names always the same as the project directory they're in? If so, it really seems like this should be the default behavior for Pipenv.
Are Pipenv virtualenv names always the same as the project directory they're in? If so, it really seems like this should be the default behavior for Pipenv.
They virtualenv's themselves aren't always located in the project directory - by default it puts them all in .local/share/virtualenvs/
but they are named to match the directory of the project they were created for (with an added hash)
So yes, I agree this should probably be the default :)
+1
@jdkram @yozlet @Psykar @fmaida I've pushed a change to the feature/pretty-pipenv
branch which suppresses the virtualenv name if it matches a folder in the current pwd
. Do you mind checking that branch out and seeing whether this does what you're looking for?
@bobthecow great, thanks for new feature! I've given it a test but unfortunately haven't been able to get it to work with pipenv.
I originally suggested this one when I was using macOS as my daily driver, but I've jumped ship to Windows for now. In order to give it a go I dug out a Raspberry Pi with a clean raspbian lite install and have completed the following steps:
sudo apt-get install fish
curl -L https://get.oh-my.fish | fish
omf install bobthefish
pip install --user pipenv
,feature/pretty-pipenv
branch
cd ~/.local/share/omf/themes/bobthefish/
git checkout feature/pretty-pipenv
(eyeballed file to check it updated)mkdir ~/code/an-even-longer-project-name-like-wow-how-silly
cd ~/code/an-even-longer-project-name-like-wow-how-silly
pipenv install requests
pipenv shell
pip3 install virtualfish
eval (python3 -m virtualfish)
to ~/.config/fish/config.fish
cd ~/code/an-even-longer-project-name-like-wow-how-silly
vf activate an-even-longer-project-name-like-wow-how-silly
Long prompts: pipenv: virtualfish:
Here's a big ol' recording of it all:
Side note, it looks like pipenv truncates virtualenvs to 44 chars, then shoves a hash on the end. Sample echo $VIRTUAL_ENV
:
/home/jdkram/.local/share/virtualenvs/an-even-longer-project-name-like-wow-how-s-U8seY7Eh
Gotcha. I was accounting for the hash, but not the truncation. I’m not sure why the short virtualenv wasn’t working though.
Could you get the output of pwd
and echo $VIRTUAL_ENV
for me?
Sure thing. From inside pipenv shell
:
long-dir-name1
:
pwd
: /home/jdkram/code/long-dir-name
echo $VIRTUAL_ENV
: /home/jdkram/.local/share/virtualenvs/long-dir-name-WJq9guV_
an-even-longer-project-name-like-wow-how-silly
pwd
: /home/jdkram/code/an-even-longer-project-name-like-wow-how-silly
echo $VIRTUAL_ENV
: /home/jdkram/.local/share/virtualenvs/an-even-longer-project-name-like-wow-how-s-PPmhA6uF
Pipenv can produce some bananas long virtualenv names (see below), so to keep the prompt a usable length I modified line 693 of fish_prompt.fish to naively just print the glyph, as I tend to only care about whether pipenv is active. Would it be possible to suggest that bobthefish has a flag for shortening pipenv names in a similar manner to long directory paths, or a flag to omit the name entirely?
I would like to give this a shot myself, but I'm afraid I'm a complete novice with writing scripts for fish, so I'm struggling to see how I might implement the flags.
Here are the example prompts:
Thanks for the wonderful theme - it's made the terminal a much nicer place to live 😁