Issue #27 resolved

Add optional creation of sub shell

Jannis Leidel
created an issue

The tool "loadenv" [1] has an intriguing way of enabling a virtualenv by creating a subshell, allowing to "deactivate" a virtualenv by simply exiting it. It uses bash's {{{--rcfile}}} flag.


Comments (7)

  1. Doug Hellmann repo owner

    That's a neat idea. I'd want to make sure it could be implemented for all supported shells (bash, sh, & zsh).

    Do you think it should be a separate command, or an option to workon? For example, "loadenv foo" or "workon -s foo"?

  2. Jannis Leidel reporter

    Personally, I'd prefer a separate command (e.g. "enterenv" or "loadenv") since it's definitely a different kind of handling virtualenvs and might lead to confusion if added to "workon".

  3. Anonymous

    Here's a quick pass at a patch for this. virtualenv isn't loving my Homebrew config so this is thoroughly untested. The biggest issue I see is the lack of running deactivate hooks. I don't see a sure fire way to make sure they're run in the subshell before exiting, and running them in the control shell seems like it'd be ungood.

    I don't see a button for attaching files so I'm gonna pray that one shows up after I click the submit button.

  4. Doug Hellmann repo owner

    Based on a quick scan of manual pages this morning, it looks like the only portable way to ensure both a startup and teardown phase in all the supported shells (bash, sh, zsh, and soon ksh) would be to run 2 shells. Something like:

    $SHELL -i <<EOF
    workon $*
    $SHELL -i

    although the nested shell in that example exits immediately for some reason. Maybe it gets the end-of-file as well, I'm not sure.

  5. Log in to comment