Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggest: prettify long pipenv names #174

Open
jdkram opened this issue Oct 12, 2018 · 8 comments
Open

Feature suggest: prettify long pipenv names #174

jdkram opened this issue Oct 12, 2018 · 8 comments

Comments

@jdkram
Copy link

jdkram commented Oct 12, 2018

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:
image

Thanks for the wonderful theme - it's made the terminal a much nicer place to live 😁

@yozlet
Copy link

yozlet commented Oct 29, 2018

+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.

@bobthecow
Copy link
Member

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.

@Psykar
Copy link

Psykar commented Apr 1, 2019

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 :)

@fmaida
Copy link

fmaida commented Feb 29, 2020

+1

bobthecow added a commit that referenced this issue Mar 21, 2020
@bobthecow
Copy link
Member

@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?

@jdkram
Copy link
Author

jdkram commented Mar 22, 2020

@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.

config

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:

  1. install fish, oh-my-fish, bobthefish, pipenv
    • sudo apt-get install fish
    • curl -L https://get.oh-my.fish | fish
    • omf install bobthefish
    • pip install --user pipenv,
  2. switch to feature/pretty-pipenv branch
    • cd ~/.local/share/omf/themes/bobthefish/
    • git checkout feature/pretty-pipenv (eyeballed file to check it updated)
    • reboot system and ssh back in
  3. create sample long dir and initialise
    • 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
    • check prompt length
  4. try with virtualfish over pipenv:
    • pip3 install virtualfish
    • add eval (python3 -m virtualfish) to ~/.config/fish/config.fish
    • re-ssh in
    • cd ~/code/an-even-longer-project-name-like-wow-how-silly
    • vf activate an-even-longer-project-name-like-wow-how-silly
    • check prompt length

results

Long prompts:
pipenv:
image
virtualfish:
image

Here's a big ol' recording of it all:
asciicast

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

@bobthecow
Copy link
Member

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?

@jdkram
Copy link
Author

jdkram commented Mar 23, 2020

Sure thing. From inside pipenv shell:

  • for long-dir-name1:
    • pwd: /home/jdkram/code/long-dir-name
    • echo $VIRTUAL_ENV: /home/jdkram/.local/share/virtualenvs/long-dir-name-WJq9guV_
  • for 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants