0

Installed virtualenv on my work computer (to which I don't have admin rights) so that I could experiment with Python in my down time during my shift. I typically create different environments for different modules, like scrapy, twisted, flask, etc.

However, once in the environment, and I start traversing directories, I notice that I'm quickly running out of space in Windows' cmd terminal...

(scrapes) C:\Users\Me\Documents\code\scrapes\spiderman\spiderman\spiders\>

Since I can see that my virtual environment is started from \scrapes by the far left prompt, and since I generally don't care about anything outside my environment once I'm in it, I was wondering if anyone had a way of changing the prompt to something a little more palpable; say:

(scrapes) ~\spiderman\spiderman\spiders\>

In other words, I'm to summarize up to the virtualenv folder, replacing it in this case with a ~.

It appears that the prompt is altered using the environments's activate script (scrapes\Scripts\activate):

activate.bat:

@echo off
set "VIRTUAL_ENV=C:\Users\Me\Documents\code\scrapes"

if defined _OLD_VIRTUAL_PROMPT (
    set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
) else (
    if not defined PROMPT (
        set "PROMPT=$P$G"
    )
    set "_OLD_VIRTUAL_PROMPT=%PROMPT%"  
)
set "PROMPT=(scrapes) %PROMPT%"

if not defined _OLD_VIRTUAL_PYTHONHOME (
    set "_OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%"
)
set PYTHONHOME=

if defined _OLD_VIRTUAL_PATH (
    set "PATH=%_OLD_VIRTUAL_PATH%"
) else (
    set "_OLD_VIRTUAL_PATH=%PATH%"
)
set "PATH=%VIRTUAL_ENV%\Scripts;%PATH%"

:END

It seems like to me that this would only affect the prompt for this environment. If anyone could find a way to summarize paths as a default action of virtualenv, that would be seriously cool

dbishop
  • 910
  • 2
  • 8
  • 13
  • Somewhat related question: http://stackoverflow.com/questions/10406926/how-to-change-default-virtualenvwrapper-prompt I believe the same would work for Windows although the syntax would be slightly different. – Wolph Sep 23 '15 at 09:02
  • @Wolph I took a brief look at this prior to posting my question, my only concern being that it appears to have only solutions regarding bash. I was able to find a .bat file withing `scrapes\Scrapes\ that appears to be what alters the prompt, but I know next to nothing about .bat scripting – dbishop Sep 23 '15 at 09:05
  • Post a link to the .bat scrapes uses and someone might be able to help you. – martineau Sep 23 '15 at 10:17
  • The closest I've found it the `prompt $g` command - See http://superuser.com/questions/315354/how-do-i-hide-the-path-in-command-line-prompt-on-windows – Mike Driscoll Sep 23 '15 at 16:43
  • 2
    Customizing cmd's prompt dynamically is limited to a set of predefined codes, e.g. the default prompt is `$P$G` (current path, greater-than sign). You could change it to `[$P]$_$G`, which prints the path in brackets, and then prints the greater-than sign on the next line. Run `prompt /?` to see the full list of codes. – Eryk Sun Sep 23 '15 at 16:52
  • To persist the setting in `HKCU\Environment`, run `setx PROMPT "%PROMPT%"`. – Eryk Sun Sep 23 '15 at 17:06

0 Answers0