Skip to content

Changed workon's env switching to use OR not $? #59

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

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions virtualenvwrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -759,16 +759,14 @@ function workon {
# before switching so we use our override function,
# if it exists, but make sure it's the deactivate function
# we set up
type deactivate >/dev/null 2>&1
if [ $? -eq 0 ]
then
! type deactivate >/dev/null 2>&1 || {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this { start a sub shell?

Copy link
Contributor Author

@Nealium Nealium May 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, sidetracked, was this determined to be in a subshell?

I'm finding the whole topic of determining if it is/isn't confusing and unclear.
$BASH_SUBSHELL seems to indicate it is not. It's not in parentheses and it's not a pipe, so I don't see any reason why it would be

Do subshells potentially raise a bunch of potential problems?- I'm just curious, tidbits and all.

edit: grammar

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a sub shell, then actions in the braces don't affect the current shell. Running and then unsetting deactivate won't actually do anything.

https://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html#Command-Grouping seems to indicate that {} does not create a new subshell.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay! I thought it may have been a compatibility issue, some niche situation or even just bad practice.

I've been daily driving this change, so I know it at least fundamentally works (at least in my env)

typeset -f deactivate | grep 'typeset env_postdeactivate_hook' >/dev/null 2>&1
if [ $? -eq 0 ]
then
deactivate
unset -f deactivate >/dev/null 2>&1
fi
fi
}

virtualenvwrapper_run_hook "pre_activate" "$env_name"

Expand Down