mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 08:55:52 +08:00
Find fishd file even when $HOME is unset
env.cpp sets up $HOME based on the current user, if it's not inherited from the environment. fishd_get_config should be using the same calculated value of $HOME. To that end, move universal variable initialization to after $HOME is set up, and read the value from the fish environment instead of using getenv(). Fixes #1725.
This commit is contained in:
parent
1be5e68e99
commit
43e451d4d8
10
env.cpp
10
env.cpp
|
@ -530,11 +530,6 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
|
||||||
env_set(L"version", version.c_str(), ENV_GLOBAL);
|
env_set(L"version", version.c_str(), ENV_GLOBAL);
|
||||||
env_set(L"FISH_VERSION", version.c_str(), ENV_GLOBAL);
|
env_set(L"FISH_VERSION", version.c_str(), ENV_GLOBAL);
|
||||||
|
|
||||||
/* Set up universal variables. The empty string means to use the deafult path. */
|
|
||||||
assert(s_universal_variables == NULL);
|
|
||||||
s_universal_variables = new env_universal_t(L"");
|
|
||||||
s_universal_variables->load();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Set up SHLVL variable
|
Set up SHLVL variable
|
||||||
*/
|
*/
|
||||||
|
@ -570,6 +565,11 @@ void env_init(const struct config_paths_t *paths /* or NULL */)
|
||||||
/* Set PWD */
|
/* Set PWD */
|
||||||
env_set_pwd();
|
env_set_pwd();
|
||||||
|
|
||||||
|
/* Set up universal variables. The empty string means to use the deafult path. */
|
||||||
|
assert(s_universal_variables == NULL);
|
||||||
|
s_universal_variables = new env_universal_t(L"");
|
||||||
|
s_universal_variables->load();
|
||||||
|
|
||||||
/* Set g_log_forks */
|
/* Set g_log_forks */
|
||||||
env_var_t log_forks = env_get_string(L"fish_log_forks");
|
env_var_t log_forks = env_get_string(L"fish_log_forks");
|
||||||
g_log_forks = ! log_forks.missing_or_empty() && from_string<bool>(log_forks);
|
g_log_forks = ! log_forks.missing_or_empty() && from_string<bool>(log_forks);
|
||||||
|
|
|
@ -547,28 +547,12 @@ bool env_universal_t::move_new_vars_file_into_place(const wcstring &src, const w
|
||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Get environment variable value.
|
|
||||||
*/
|
|
||||||
static env_var_t fishd_env_get(const char *key)
|
|
||||||
{
|
|
||||||
const char *env = getenv(key);
|
|
||||||
if (env != NULL)
|
|
||||||
{
|
|
||||||
return env_var_t(str2wcstring(env));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return env_var_t::missing_var();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static wcstring fishd_get_config()
|
static wcstring fishd_get_config()
|
||||||
{
|
{
|
||||||
bool done = false;
|
bool done = false;
|
||||||
wcstring result;
|
wcstring result;
|
||||||
|
|
||||||
env_var_t xdg_dir = fishd_env_get("XDG_CONFIG_HOME");
|
env_var_t xdg_dir = env_get_string(L"XDG_CONFIG_HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||||
if (! xdg_dir.missing_or_empty())
|
if (! xdg_dir.missing_or_empty())
|
||||||
{
|
{
|
||||||
result = xdg_dir;
|
result = xdg_dir;
|
||||||
|
@ -580,7 +564,7 @@ static wcstring fishd_get_config()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
env_var_t home = fishd_env_get("HOME");
|
env_var_t home = env_get_string(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||||
if (! home.missing_or_empty())
|
if (! home.missing_or_empty())
|
||||||
{
|
{
|
||||||
result = home;
|
result = home;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user