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
How to set $PATH persistently? #527
Comments
I think it's because PATH variable is handled specially in Fish. So you can't make it universal etc. I am not aware about the reasons behind it. May be @ridiculousfish or @JanKanis would like to say few words about it. On Linux I set PATH in ~/.config/fish/config.fish this way :
|
in your |
Ah. I was just wondering if there was a neatly interactive/"live" way to do it. |
On 18 January 2013 21:07, Dag Odenhall notifications@github.com wrote:
|
Yea I was looking in the wrong page. I edited that comment but github sent the mail notification faster. |
When fish starts, it modifies PATH to include its bin directory. We really want to be able to tell users that they can permanently modify PATH via |
Since setting $PATH is very common, I think it's important to have a story for fish 2.0 that doesn't require the user to edit Here's what I'm thinking:
perhaps with some uniqueing to avoid duplicates. With this design, then:
I'm not super-happy with this because it requires three variables - it would be nice if there were an approach that only required $PATH. Thoughts? |
Another option that came to mind (though I'm not necessarily advocating for Another design choice could be to rename $fish_user_paths to the universal On 8 February 2013 23:17, ridiculousfish notifications@github.com wrote:
|
Having a universal PATH that just accumulates seems harmless. Another thought I had was to try to fix fish so it doesn't depend on PATH to find its own binaries. Then it wouldn't need to modify PATH at all. |
It strikes me that PATH ought never to be a universal variable, because it must be inherited from the environment. That is, if someone sets PATH in bash and then invokes fish, fish ought to respect that, and not overwrite it a universal value. Here's what I ended up doing:
So this is similar to my proposal, except we don't need fish_default_paths. And I think the separation between "here's stuff from the environment" and "here's stuff to add to it" is good. I also like that it required no changes to fish proper, just to config.fish. So now to append to PATH persistently, append to fish_user_paths, e.g. To git@github.com:fish-shell/fish-shell.git |
Is there a reason we don't prepend to |
In fish 2.1, we do prepend. |
@saulshanabrook: Already fixed with issue #888. Anyway, I think that universal |
Not having PATH simply changeable by a normal user action is a major issue and contrary to the beautiful simplicity of fish relative to other shells. Please fix this. It is really a royal pain. I want to set the path and have it work from then on at least in current session if not universally. Do you know how much of a surprise it is that |
Part of the surprise is due to the fact that you can set universal variables and have global variables override them without warning; perhaps at least in interactive mode we should warn when setting a global or universal variable that has a more specifically-scoped variable with the same name set. This has bitten other variables as well, such as |
EDIT: I just realized this is mentioned above. If you just want to set the path for the current session, omit the scope and just do If you want to persistently add paths you do this through manipulating |
If I set something in @ridiculousfish stated in fish 2.1 values from This is causing slightly whacky behaviour on my system since The brew plugin in bpinto/oh-my-fish fixes it though but still. |
CorrectionThe handler for set --universal fish_user_paths $fish_user_paths ~/path/name Original postAfter some reading and playing around with trying to figure out the "best" way to persistently add a path to your $PATH, I think @terlar's suggestion is best. That is set fish_user_paths $fish_user_paths my_path
|
|
Thank you @dideler, following works fine for adding rvm again:
|
Hm, well, I just did |
@NikhilVerma it's easier to just shadow |
SET fish_user_paths:/Users/sztadhaus/Library/Android/sdk worked for me! |
Something I discovered today is that
|
When this is done, the fish_variables file is updated with something like: The problem I have is that I want to sync my whole Another question is why |
Unfortunately, the value will be expanded when set, and the tilde won't be expanded later, because that's not how $PATH works (the entry would be broken for every other program, with the exception of bash). That means this won't work, so you'll have to use a global variable for it and set it in config.fish.
Fish does not set $PATH by default - it inherits it from your environment. Which is a good default because that means fish gets the same $PATH as other shells. If you want ~/.local/bin to be added by default, ask your distribution to add it, or edit e.g. /etc/login.defs. |
@faho thanks for the great answer. In regards to edit: sorry I just realized this discussion is off topic. |
A bit more off-topic stuff, but… my universal variable I am using fish 3.0.2.
|
@spider-mario it's ok to open a new issue, or to ask on Super User or a similar forum. Your problem is that you have exported a universal variable; this is almost always wrong because it leaks into child fish processes as a global variable. |
I have to google this every time and I always end up reading through this thread. I suggest adding a command like |
@boxed i've been trying to get myself adjusted to fish for about two months now. I must've landed on this thread at least a dozen times. |
|
#!/usr/bin/env fish
if argparse -n 'fish-add-user-path' -N 1 'h/help' -- $argv
;
else
exit
end
function add_to_path_if_not_there
set exists 0
# normalize path to end with /
switch $argv
case "*/"
set new_path $argv
case "*"
set new_path "$argv/"
end
for x in (string split " " $fish_user_paths)
if test "$x" = "$new_path"
set exists 1
break
end
end
if test "$exists" = "0"
set -Ux fish_user_paths $fish_user_paths $new_path
end
end
# validate that paths exists
for x in (string split " " $argv)
if test -d $x
;
else
echo "Path '$x' does not exist"
exit
end
end
for x in (string split " " $argv)
add_to_path_if_not_there $x
end This is the first fish script I wrote so I'm pretty sure it's crap! But it does do The Right Thing mostly. If you pass it several invalid paths it only complains about the first one, not all of them. And it might be a good idea if it can accept invalid paths if you pass a flag.. maybe. But otherwise this seems to work, even if it's ugly :P |
* Previous syntax was keeping asdf from adding itself at the beginning of the path. * Reference: fish-shell/fish-shell#527 (comment)
* Previous syntax was keeping asdf from adding itself at the beginning of the path. * Reference: fish-shell/fish-shell#527 (comment)
Changing the scope flag from "export" to "global" seems to fix the issue. See also fish-shell/fish-shell#527 (comment) for reference
@spider-mario I'm not sure if this addresses your issue, but I added echo "set -eg fish_user_paths" >> ~/.config/fish/config.fish |
Cleanup config.fish: - Remove old commended lines - Better way to set $PATH variable (fish-shell/fish-shell#527 (comment))
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sure, a function is nice, but here is a quick abbreviation that I like just as much.
usage: |
@ElijahLynn that doesn't validate the path and it's not idempotent. |
Can't we reopen this? There is a bad UX problem here. Fish normally cares about this stuff! |
@boxed this issue has been pulled in many directions so I am going to lock it. I agree PATH often trips people up and there are probably things that can be improved about it. If you have a suggestion for improving how PATH gets set, please open a new issue. |
To prepend to $PATH persistently, since fish 3.2.0:
Top comment hijacked by @faho and @ridiculousfish to help people landing here from search engines. Original comment follows:
I try
set -U PATH ~/.cabal/bin $PATH
which sets it in the shell I type it in, but not any new shells I launch and it's gone if I restart the first shell as well.Using git HEAD on Fedora 18.
The text was updated successfully, but these errors were encountered: