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

shellenv: use PATH variable, fish_user_paths should remain universal #7215

Merged
merged 1 commit into from Mar 27, 2020
Merged

shellenv: use PATH variable, fish_user_paths should remain universal #7215

merged 1 commit into from Mar 27, 2020

Conversation

charego
Copy link
Contributor

@charego charego commented Mar 25, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

There are two ways to manipulate PATH in fish shell.

  • set the PATH variable directly
  • set the fish_user_paths variable, whose contents are automatically prepended to PATH

fish_user_paths is supposed to be a universal variable.

> set --show fish_user_paths
$fish_user_paths: not set in local scope
$fish_user_paths: not set in global scope
$fish_user_paths: set in universal scope, unexported, with 1 elements
$fish_user_paths[1]: length=20 value=|/home/charego/fzf/bin|

When you evaluate the output of shellenv, fish_user_paths is set as a global variable which shadows the universal variable. This is technically legal, but it goes against best practice and causes issues when the user wants to update fish_user_paths in the future.

> eval (/home/linuxbrew/.linuxbrew/bin/brew shellenv)

> set --show fish_user_paths
$fish_user_paths: not set in local scope
$fish_user_paths: set in global scope, unexported, with 3 elements
$fish_user_paths[1]: length=30 value=|/home/linuxbrew/.linuxbrew/bin|
$fish_user_paths[2]: length=31 value=|/home/linuxbrew/.linuxbrew/sbin|
$fish_user_paths[3]: length=20 value=|/home/charego/fzf/bin|
$fish_user_paths: set in universal scope, unexported, with 1 elements
$fish_user_paths[1]: length=20 value=|/home/charego/fzf/bin|

> echo $fish_user_paths
/home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/sbin /home/charego/fzf/bin
> set -U fish_user_paths ~/bin $fish_user_paths
set: Universal variable 'fish_user_paths' is shadowed by the global variable of the same name.

> set --show fish_user_paths
$fish_user_paths: not set in local scope
$fish_user_paths: set in global scope, unexported, with 3 elements
$fish_user_paths[1]: length=30 value=|/home/linuxbrew/.linuxbrew/bin|
$fish_user_paths[2]: length=31 value=|/home/linuxbrew/.linuxbrew/sbin|
$fish_user_paths[3]: length=20 value=|/home/charego/fzf/bin|
$fish_user_paths: set in universal scope, unexported, with 4 elements
$fish_user_paths[1]: length=16 value=|/home/charego/bin|
$fish_user_paths[2]: length=30 value=|/home/linuxbrew/.linuxbrew/bin|
$fish_user_paths[3]: length=31 value=|/home/linuxbrew/.linuxbrew/sbin|
$fish_user_paths[4]: length=20 value=|/home/charego/fzf/bin|

> echo $fish_user_paths
/home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/sbin /home/charego/fzf/bin

For this reason it makes sense that shellenv should output instructions to update the PATH variable directly instead of fiddling with fish_user_paths.

Reference: fish shell tutorial, $PATH section

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Nice work! One suggested tweak. Thanks!

echo "set -g fish_user_paths \"$HOMEBREW_PREFIX/bin\" \"$HOMEBREW_PREFIX/sbin\" \$fish_user_paths;"
echo "set -q MANPATH; or set MANPATH ''; set -gx MANPATH \"$HOMEBREW_PREFIX/share/man\" \$MANPATH;"
echo "set -q INFOPATH; or set INFOPATH ''; set -gx INFOPATH \"$HOMEBREW_PREFIX/share/info\" \$INFOPATH;"
echo "contains \"$HOMEBREW_PREFIX/sbin\" \$PATH; or set -gx PATH \"$HOMEBREW_PREFIX/sbin\" \$PATH;"
Copy link
Member

Choose a reason for hiding this comment

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

Can we kill the contains? We don't do that for anything else and it seems overkill.

Copy link

@faho faho Mar 25, 2020

Choose a reason for hiding this comment

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

It is not overkill, it should be done for the rest as well.

Fish loads its config always, whether login or not, interactive or not. That means this could easily result in growing $*PATH.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @MikeMcQuaid, I didn't want to modify the shellenv output too much and was planning to not use contains, but discussion on the fish gitter led me to include it. As @faho explained the PATH variables will continue to grow if you open fish within fish, for example. Thanks for the review.

Copy link
Member

Choose a reason for hiding this comment

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

As @faho explained the PATH variables will continue to grow if you open fish within fish, for example.

This also applies to Bash and ZSH and no-one has complained about this until this PR.

Can we scope this just to PATH for now, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Scope is limited to PATH variable for fish shell only.

@MikeMcQuaid
Copy link
Member

Thanks so much for your first contribution! Without people like you submitting PRs we couldn't run this project. You rock, @charego!

@MikeMcQuaid MikeMcQuaid merged commit 0945447 into Homebrew:master Mar 27, 2020
@lock lock bot added the outdated PR was locked due to age label May 5, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants