oh-my-fish / theme-bobthefish

A Powerline-style, Git-aware fish theme optimized for awesome.
MIT License
1.46k stars 226 forks source link

Feature suggest: prettify long pipenv names #174

Open jdkram opened 6 years ago

jdkram commented 6 years ago

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

bobthecow commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

+1

bobthecow commented 4 years ago

@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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

Sure thing. From inside pipenv shell: