Fix: Use copy of os.environ to avoid mutating env #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi! Thanks for maintaining this, it's quite useful.
I found that the xontrib modifies environment variables in a way that is probably not desired.
I set my $FZF_DEFAULT_OPTS to the following:
This uses
bat
to display a nice file preview:The issue is that in a xonsh session, after using the file searcher (which modifies
$FZF_DEFAULT_OPTS
to include the default args), the args are carried over to the command history search. It then tries to fetch a preview for commands, which doesn't work, and I imagine could lead to unintended commands being run.This PR modifies the code to use
dict(os.environ)
instead ofos.environ
directly, so that we can modify a copy without affecting env vars. Althoughos.environ
is its own class and not a dict,subprocess.run
takes a mapping as per the documentation:And I've tested this to verify it now works as expected.