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 reading of /etc/paths on OS X #4852
Conversation
This is the follow-up promised in #4337 (comment) . |
share/functions/path_helper.fish
Outdated
# see __fish_construct_path in config.fish and | ||
# https://opensource.apple.com/source/shell_cmds/shell_cmds-203/path_helper/path_helper.c.auto.html . | ||
|
||
function __quote -d "single-quote arguments, escaping characters as necessary" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a built-in way to quote a string. Thought string escape
would do it, but it does something different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string escape
will do what you want - escape a string so that it'll pass through source
unharmed. It just doesn't always use single-quotes. Instead it falls back to using \\
for more complicated things.
However, I'm not quite sure why this path_helper
function exists at all - you're not using it anywhere as far as I can see, and since it would run in the fish process, there's no need to output the set statements - instead, you could just directly run them. Which would also remove the need for quoting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a driver for debugging the path_helper logic without having to start shells and examine environment variables. I can remove it if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please! This looks like something to invoke, and it really shouldn't be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Please take another look.
share/functions/path_helper.fish
Outdated
|
||
function __quote -d "single-quote arguments, escaping characters as necessary" | ||
for x in $argv | ||
set -l quoted (string replace -a -r '([\\\\\'])' '\\\\\\\\$1' $x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly sure why I need to triple-escape the \
in \\\\\\\\$1
; need to escape once because it's in a single-quoted string, another because it's a replacement string for a regexp, but I can't think of a reason for a third escape.
Pinging original main reviewer @krader1961. |
|
@ridiculousfish is probably the best reviewer here. |
Thanks for doing this! Can you please catch me up on the rationale? |
Sure thing! My previous PR #4337 took the approach of parsing
If you compare this PR to #4337 , this one does seem simpler to understand. The danger of our behavior diverging from However, if you prefer the other approach, I could always resurrect #4337 . |
share/config.fish
Outdated
end | ||
|
||
for x in $result | ||
echo $x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This entire for-loop could also be replaced with set -xg $argv[1] $result
- then the outer set
becomes unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done!
This looks quite nice to me. Unfortunately, I can't really test it, so I'll leave that up to @ridiculousfish! |
@akalin thanks for the explanation. I'm on board with emulating |
Implement it just for PATH.
@ridiculousfish Per @faho's suggestion, I removed the path_helper function; I had it around only for debugging. Please take another look! |
Looks good. Squash-merged as adbaddf. Thanks!! |
Note that this changes the behaviour from running for all shells to running for login shells only. This matches the behaviour for other shells but breaks sessions run using iTerm2's "run command" option, for example. |
@zanchey how do people using other shells solve the problem? Perhaps we could expose a function for people to call (that does what this PR does for a login shell) if they want that behavior? |
Hi, just to be clear, I made it login-shell-only to match the behavior of sh/bash (since the call to |
Nothing is really intended. I reverted that because it looked like an undocumented behavior change, and zanchey observed that it broke a use case ("Run Command" in iTerm2). Nobody has made a case for what the right behavior should be, so it's better to not break any users who might be depending on the existing behavior. |
(and /etc/paths.d/*)
Do so by emulating the behavior of /usr/libexec/path_helper for login shells,
matching the behavior in /etc/profile.
Also add a path_helper command to reproduce the behavior of
/usr/libexec/path_helper for fish.
This also handles setting MANPATH if necessary.
Fixes issue #4336
TODOs: