mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
env.cpp: Better fallback for missing PATH
Ask the system where utilities are available with confstr (POSIX). This is the same string printed by `getconf PATH`, which likely includes more directories.
This commit is contained in:
parent
4567d3ae52
commit
290d07a833
1 changed files with 9 additions and 2 deletions
11
src/env.cpp
11
src/env.cpp
|
@ -649,8 +649,15 @@ static void setup_path() {
|
|||
auto &vars = env_stack_t::globals();
|
||||
const auto path = vars.get(L"PATH");
|
||||
if (path.missing_or_empty()) {
|
||||
wcstring_list_t value({L"/usr/bin", L"/bin"});
|
||||
vars.set(L"PATH", ENV_GLOBAL | ENV_EXPORT, value);
|
||||
#if defined(_CS_PATH)
|
||||
// _CS_PATH: colon-separated paths to find POSIX utilities
|
||||
std::string cspath;
|
||||
cspath.resize(confstr(_CS_PATH, nullptr, 0));
|
||||
confstr(_CS_PATH, &cspath[0], cspath.length());
|
||||
#else
|
||||
std::string cspath = "/bin:/usr/bin"; // shouldn't really happen
|
||||
#endif
|
||||
vars.set_one(L"PATH", ENV_GLOBAL | ENV_EXPORT, str2wcstring(cspath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue