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

prevent same entry in $env.PATH #1104

Merged
merged 4 commits into from Oct 8, 2023
Merged

prevent same entry in $env.PATH #1104

merged 4 commits into from Oct 8, 2023

Conversation

joergsch
Copy link
Contributor

@joergsch joergsch commented Oct 8, 2023

if one extends PATH in env.nu and start a different shell before launching nu, one might start to collect the same path multiple times in PATH these lines construct the new value (based on home directory and the separator based on the os)

if one extends PATH in `env.nu` and start a different shell before launching nu, one might start to collect the same path multiple times in PATH
these lines construct the new value (based on home directory and the separator based on the os)
@fdncred
Copy link
Collaborator

fdncred commented Oct 8, 2023

Seems like this part $env.my_path = ... should be let my_path = .... I'm not sure why we'd create an env var just to add it to the $env.PATH.

@joergsch
Copy link
Contributor Author

joergsch commented Oct 8, 2023

Seems like this part $env.my_path = ... should be let my_path = .... I'm not sure why we'd create an env var just to add it to the $env.PATH.

There is no benefit creating an additional env var.
my bad (still learning nu)

Copy link
Member

@amtoine amtoine left a comment

Choose a reason for hiding this comment

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

thanks for adding this, that can be quite handy to not have multiple times the same path in $env.PATH for some applications 😋

just two remarks and i'd be good to go 😌

book/configuration.md Outdated Show resolved Hide resolved
book/configuration.md Outdated Show resolved Hide resolved
@amtoine
Copy link
Member

amtoine commented Oct 8, 2023

@joergsch
and if you want to go extra fancy, you can define a more general custom command for this 😏

def prepend-if-not-in [element: any]: list<any> -> list<any> {
    if $element in $in { $in } else { $in | prepend $element }
}

$env.PATH = ($env.PATH | prepend-if-not-in ($nu.home-path | path join "bin"))

joergsch and others added 3 commits October 8, 2023 19:07
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
@amtoine
Copy link
Member

amtoine commented Oct 8, 2023

thanks for this new section @joergsch, let's land this 🙏

@amtoine amtoine merged commit 7de06b4 into nushell:main Oct 8, 2023
2 checks passed
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.

None yet

3 participants