aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/env.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/env.cpp')
-rw-r--r--src/env.cpp44
1 files changed, 20 insertions, 24 deletions
diff --git a/src/env.cpp b/src/env.cpp
index c7924aef..0ec45448 100644
--- a/src/env.cpp
+++ b/src/env.cpp
@@ -174,16 +174,14 @@ static bool var_is_locale(const wcstring &key) {
static void handle_locale(const wchar_t *env_var_name) {
debug(2, L"handle_locale() called in response to '%ls' changing", env_var_name);
const char *old_msg_locale = setlocale(LC_MESSAGES, NULL);
-
- for (size_t i = 0; locale_variable[i]; i++) {
- const wchar_t *key = locale_variable[i];
- const env_var_t var = env_get_string(key);
- if (!var.empty()) {
- const std::string &name = wcs2string(key);
- const std::string &value = wcs2string(var);
- setenv(name.c_str(), value.c_str(), 1);
- debug(3, L"locale var %s='%s'", name.c_str(), value.c_str());
- }
+ const env_var_t val = env_get_string(env_var_name, ENV_EXPORT);
+ const std::string &value = wcs2string(val);
+ const std::string &name = wcs2string(env_var_name);
+ debug(2, L"locale var %s='%s'", name.c_str(), value.c_str());
+ if (val.empty()) {
+ unsetenv(name.c_str());
+ } else {
+ setenv(name.c_str(), value.c_str(), 1);
}
char *locale = setlocale(LC_ALL, "");
@@ -216,15 +214,14 @@ static bool var_is_curses(const wcstring &key) {
/// libraries.
static void handle_curses(const wchar_t *env_var_name) {
debug(2, L"handle_curses() called in response to '%ls' changing", env_var_name);
- for (size_t i = 0; curses_variable[i]; i++) {
- const wchar_t *key = curses_variable[i];
- const env_var_t var = env_get_string(key);
- if (!var.empty()) {
- const std::string &name = wcs2string(key);
- const std::string &value = wcs2string(var);
- setenv(name.c_str(), value.c_str(), 1);
- debug(3, L"curses var %s='%s'", name.c_str(), value.c_str());
- }
+ const env_var_t val = env_get_string(env_var_name, ENV_EXPORT);
+ const std::string &name = wcs2string(env_var_name);
+ const std::string &value = wcs2string(val);
+ debug(2, L"curses var %s='%s'", name.c_str(), value.c_str());
+ if (val.empty()) {
+ unsetenv(name.c_str());
+ } else {
+ setenv(name.c_str(), value.c_str(), 1);
}
// TODO: Modify input_init() to allow calling it when the terminfo env vars are dynamically
// changed. At the present time it can be called just once. Also, we should really only do this
@@ -318,11 +315,10 @@ static bool variable_is_colon_delimited_array(const wcstring &str) {
}
void env_init(const struct config_paths_t *paths /* or NULL */) {
- // env_read_only variables can not be altered directly by the user.
+ // These variables can not be altered directly by the user.
const wchar_t *const ro_keys[] = {
- L"status", L"history", L"_", L"LINES", L"COLUMNS", L"PWD",
- // L"SHLVL", // will be inserted a bit lower down
- L"FISH_VERSION",
+ L"status", L"history", L"_", L"LINES", L"COLUMNS", L"PWD", L"FISH_VERSION",
+ // L"SHLVL" is readonly but will be inserted below after we increment it.
};
for (size_t i = 0; i < sizeof ro_keys / sizeof *ro_keys; i++) {
env_read_only.insert(ro_keys[i]);
@@ -339,7 +335,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
global_env = top;
global = &top->env;
- // Now the environemnt variable handling is set up, the next step is to insert valid data.
+ // Now the environment variable handling is set up, the next step is to insert valid data.
// Import environment variables. Walk backwards so that the first one out of any duplicates wins
// (#2784).