Skip to content
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

Fix: Use copy of os.environ to avoid mutating env #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pedrovhb
Copy link

@pedrovhb pedrovhb commented Oct 5, 2021

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:

$FZF_DEFAULT_OPTS="-m --reverse --height=40 --preview 'bat --color=always --style=numbers --line-range=:500 {}'"

This uses bat to display a nice file preview:

image

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 of os.environ directly, so that we can modify a copy without affecting env vars. Although os.environ is its own class and not a dict, subprocess.run takes a mapping as per the documentation:

If env is not None, it must be a mapping that defines the environment variables for the new process

And I've tested this to verify it now works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant