Giter VIP home page Giter VIP logo

Comments (7)

marvingreenberg avatar marvingreenberg commented on June 24, 2024

So I got a custom command working (almost). The part in the [python] section isn't supported - I guess I would have to break out the top level format string, which seems complicated.

[custom.venv]
description = "Show qualified virtualenv dir, if not IN the dir tree where it is resides"
# from directory ../project-name/, . ~/some/other/.venv/bin/activate -- displays 'other/.venv'
# from directory .../other/src, .../other, etc. , -- displays just .venv
command = """
    qual=$(basename $(dirname "$VIRTUAL_ENV"));
    venv=$(basename "$VIRTUAL_ENV");
    pat=".*/${qual}/*(/.*)?$";
    [[ "$PWD" =~ $pat ]] && printf "($venv)" || printf "($qual/$venv)"
    """
when = '''[[ -n "$VIRTUAL_ENV" ]]'''
format = '[$output](blue)'

[python]
format = '\[[${symbol}${pyenv_prefix}(${version})(\(${custom.venv}\))]($style)\]'

from starship.

jankatins avatar jankatins commented on June 24, 2024

Maybe as an alternative solution: use --prompt "name" to set a different name?

[22:01:57] λ  python -m venv .venv --prompt "whatever"

~/projects/whatever on  feature/pagination (c2c6c249)  v3.12.2 (venv:whatever)  took 5s
[22:02:10] λ

The first venv: comes from my format definition:

[python]
format = "[$symbol$version( \\(venv:$virtualenv\\))]($style) "

from starship.

marvingreenberg avatar marvingreenberg commented on June 24, 2024

Interesting. But what really motivated this was several times vscode somehow getting the venv wrong, or just changing directories. I'm sort of fine with what I already did. But I think it is a generally useful idea. I'm happy to close it if you think it's pointless, or not useful enough. As an aside, is there a way to do something like my custom command, or do I have to just rewrite the top level format string.

Btw, starship is killer.

from starship.

marvingreenberg avatar marvingreenberg commented on June 24, 2024

And here's an example of how my (badly integrated) custom venv looks...

~/g/sample-python (0bdef92) 3?  [🐍 v3.12.2]
08:53:46 ❯ . ./.venv/bin/activate

~/g/sample-python (0bdef92) 3?  [🐍 v3.12.2](.venv)
08:53:59 ❯ cd ../tws-stack-deployment

~/g/tws-stack-deployment develop 2$ 1?  [🐍 v3.12.2](sample-python/.venv)
08:54:20 ❯ . .venv/bin/activate

~/g/tws-stack-deployment develop 2$ 1?  [🐍 v3.12.2](.venv)
08:54:26 ❯ cd -
~/git/sample-python

~/g/sample-python (0bdef92) 3?  [🐍 v3.12.2](tws-stack-deployment/.venv)

Could keep all the config the same (just change the behavior of $virtualenv) or maybe add a flag option like warn_by_qualifying_virtualenv_with_directory_when_it_seems_like_it_might_be_wrong_venv: true

Again, starship is a great package, I'm fine if you prefer to "close won't fix". If I can figure out the proper way to include it in the [python] configuration, I'll add it to that issue for examples of custom scripts.

from starship.

marvingreenberg avatar marvingreenberg commented on June 24, 2024

And, BTW, here was my motivator -- I guess I should debug why my vscode config is broke

image

I don't know where it is getting its "memory" of the correct venv to use, and it isn't always wrong...

from starship.

NodeJSmith avatar NodeJSmith commented on June 24, 2024

Just want to +1 this, stumbled upon this after dealing with the same issue as @marvingreenberg. I'd love the ability to show a bit more information about the virtualenv - I name all of mine .venv, so just showing that isn't really enough for me to know that I'm in the absolutely wrong virtual environment for absolutely no reason. Also, agreed with the above, starship is killer

Edit: Maybe another potential solution would be showing the value in a certain environment variable, such as VENV_NAME or VENV_PROMPT or STARSHIP_VENV_{NAME/PROMPT} - that would let users set this on their own using whatever logic they want

from starship.

NodeJSmith avatar NodeJSmith commented on June 24, 2024

@marvingreenberg BTW your config works well enough for me, thank you for sharing it, I can finally stop wasting time finding a way to warn myself when I'm in the wrong one

from starship.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.