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

Add python virtualenv segment #11

Merged
merged 1 commit into from
Aug 9, 2016

Conversation

MichaelAquilina
Copy link
Contributor

Displays the current python virtualenv in a segment if the $VIRTUAL_ENV environment variable is set.

Example Image

@keybits
Copy link

keybits commented Aug 9, 2016

I've just tested this on OS X and it works great.

@MichaelAquilina
Copy link
Contributor Author

@agnoster any chance of merging this in?

@agnoster agnoster merged commit f3ff367 into agnoster:master Aug 9, 2016
@agnoster
Copy link
Owner

agnoster commented Aug 9, 2016

Just FYI, the style for the other prompt segments is to leave one space on either side of the text, which this doesn't seem to do - but I don't use virtual env so won't bother me ;-)

@agnoster
Copy link
Owner

agnoster commented Aug 9, 2016

Or... actually looks like the code does include spaces but it doesn't look right in the screenshot.

@MichaelAquilina
Copy link
Contributor Author

it does :) The screenshot is out of date!

@MichaelAquilina
Copy link
Contributor Author

Should I add something to the README about this?

@MichaelAquilina MichaelAquilina deleted the python_virtualenv branch August 9, 2016 14:22
@tutuca
Copy link

tutuca commented Mar 13, 2017

I've installed the latest oh-my-zsh bundle and this segment is not present, just the regular boring (virtualenv ).

image

@MichaelAquilina
Copy link
Contributor Author

are you using virtualenvwrapper @tutuca ?

@tutuca
Copy link

tutuca commented Mar 13, 2017

@MichaelAquilina the tool? yes, the zsh plugin? no. Should I?

@MichaelAquilina
Copy link
Contributor Author

MichaelAquilina commented Mar 13, 2017

@tutuca could you link to a gist of your agnoster.zsh-theme file?

If you are using antigen for example, it would be in the path:
~/.antigen/repos/https-COLON--SLASH--SLASH-github.com-SLASH-agnoster-SLASH-agnoster-zsh-theme.git/agnoster.zsh-theme

if you are not sure where it is, use find:

find ~ -name "agnoster.zsh-theme"

@tutuca
Copy link

tutuca commented Mar 14, 2017

My agnoster which is the version included in oh-my-zsh, found on ~/.oh-my-zsh/themes/agnoster.zsh-theme:
https://gist.github.com/tutuca/e50cf9108fe1e3dea8a522ac42527bec

@MichaelAquilina
Copy link
Contributor Author

For some reason your zsh-theme is different to what I put here. Check out the prompt_virtualenv function in your gist and what is in my PR: e2371ec

@tutuca
Copy link

tutuca commented Mar 14, 2017

Maybe the version didn't make it yet into oh-my-zsh...

@MichaelAquilina
Copy link
Contributor Author

no the version in oh-my-zsh has basically changed my function. My guess is to basically provide the option to disable my feature as it may have annoyed some users. Check what the value of $VIRTUAL_ENV_DISABLE_PROMPT is to see if it is causing this feature to be disabled.

@tutuca
Copy link

tutuca commented Mar 14, 2017

$VIRTUAL_ENV_DISABLE_PROMPT is set to empty on my config (by default).

@MichaelAquilina
Copy link
Contributor Author

try setting that to 1

@tutuca
Copy link

tutuca commented Mar 14, 2017

Ack, now it works but it has those ugly parens:

image

@MichaelAquilina
Copy link
Contributor Author

What does the output of echo $VIRTUAL_ENV give you?

@MichaelAquilina
Copy link
Contributor Author

MichaelAquilina commented Mar 14, 2017

Also, the prompt is in the wrong location :/ I dont know what is being done there. I wonder if someone just created an alternate implementation and never noticed this one has been updated.

@tutuca
Copy link

tutuca commented Mar 14, 2017

echo $VIRTUAL_ENV is Blank also

@drorata
Copy link

drorata commented Aug 2, 2017

I am using CONDA to manage my environment. When activating an environment, $CONDA_DEFAULT_ENV is set. How could I utilize this theme to detect the conda activated environment? Currently, I'm using powerline-shell which handles the case; check this file.

@MichaelAquilina
Copy link
Contributor Author

I am not familiar with CONDA, but I suspect it wouldnt be hard to get working with a patch. When you activate an environment, is there an env variable that specifies what your virtualenv is pointing to?

@drorata
Copy link

drorata commented Aug 2, 2017

Following version of prompt_virtualenv seems to do the trick.

prompt_virtualenv() {
  local env='';

  if [[ -n $VIRTUAL_ENV ]]; then
    env=$VIRTUAL_ENV
  fi

  if [[ -n $CONDA_DEFAULT_ENV ]]; then
    env=$CONDA_DEFAULT_ENV
  fi

  if [[ -n $env ]]; then
    prompt_segment green black
    print -Pn " $(basename $env) "
  fi
}

It is not optimal, because it has what I consider too much spacing before and after the environment's name.

@MichaelAquilina
Copy link
Contributor Author

I would open a PR with that to this repo if I were you :)

@drorata
Copy link

drorata commented Aug 3, 2017

@MichaelAquilina It seems like there's one ready... #24

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

Successfully merging this pull request may close these issues.

5 participants