question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Add active environment name to PROMPT env var (Windows Support)

See original GitHub issue

On unix/fish, when a shell is started using pipenv shell, the $VIRTUAL_ENV variable can be used to provide a visual indicator on the shell. For Example, if the users prompt is (~/folder) $ once the shell is activated using pipenv shell the prompt becomes: (~/folder) (pipenvfolder-1234) $ or similar. This currently works well with zsh/fish, etc and in general in the unix world is fairly easy to customize prompt.

On windows however, `%PROMPT% variable is used instead, and the variable is used by both cmd.exe and cmder console to add the virtual environment to the user’s prompt.

Upon activating an environment, the environment’s name is prepended to the $PROMPT var. As far as I know, this is not customizable on cmd.exe, and is not easily customizable with cmder neither.

cmd.exe behavior with virtualenv / virtualenv-wrapper

Active Environment is shown on prompt

image

cmder behavior with virtualenv / virtualenv-wrapper

Active Environment is shown on prompt

image

cmd and cmder with pipenv shell - No prompt indicator

Environment IS NOT shown anywhere on the prompt

image

image

Proposed solution

For the pipenv environment to be shown by default on the built-in cmd.exe and other windows-friendly consoles, pipenv could prepend the shell environment name to the PROMPT variable in the same way virtualenv does.

Virtualenv stores that old prompt in _OLD_VIRTUAL_PROMPT so it can restore the original on deactivate, but pipenv would not need that since the process is destroyed.

Working example on cmd.exe

image

Working example on cmder

image

I would be happy to work on a PR if the proposal is accepted.

PS: Pipenv environment works perfectly out of the box on my fish shell image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
uranusjrcommented, May 2, 2018

I agree with this (it’s an oversight Windows support is not added). Work on it! You might not need to mess with environment variables yourself, but can leverage existing scripts to do it. The activation is done in core.activate_virtualenv; try adding cases for cmd and Powershell first and see if that’s enough.

0reactions
uranusjrcommented, May 20, 2018

This should be fixed with the above PR merge. (Please correct me if I’m wrong.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting and getting Windows environment variables from the ...
To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using: set NEWVAR=SOMETHING....
Read more >
How to Setup System Environment Variables in Windows?
Click on the “New” option using the Environment Variables dialogue box. Now enter the Variable Name and its Value under the respective columns...
Read more >
set (environment variable) - Windows Commands
Displays, sets, or removes cmd.exe environment variables. If used without parameters, set displays the current environment variable settings.
Read more >
Set Environment Variable in Windows {How-To} - phoenixNAP
This tutorial covers different ways to set, view, and unset environment variables in Windows using the GUI, Command Prompt and PowerShell.
Read more >
Windows Environment Variables List: Complete List on ...
All User Profile · App Data · Common Program Files · Common Program Files(x86) · Common Program W6432 · Computer Name · Command...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found