Define read-only $pid as %self replacement

This commit is contained in:
Mahmoud Al-Qudsi 2018-03-09 03:47:28 -06:00
parent f42f7b7208
commit 90d0f91bcd

View File

@ -322,7 +322,7 @@ bool string_set_contains(const T &set, const wchar_t *val) {
/// Check if a variable may not be set using the set command.
static bool is_read_only(const wchar_t *val) {
const string_set_t env_read_only = {L"PWD", L"SHLVL", L"_", L"history", L"status", L"version"};
const string_set_t env_read_only = {L"PWD", L"SHLVL", L"_", L"history", L"status", L"version", L"pid"};
return string_set_contains(env_read_only, val);
}
@ -969,6 +969,9 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
wcstring version = str2wcstring(get_fish_version());
env_set_one(L"version", ENV_GLOBAL, version);
// Set the $pid variable (%self replacement)
env_set_one(L"pid", ENV_GLOBAL, to_string<long>(getpid()));
// Set up SHLVL variable. Not we can't use env_get because SHLVL is read-only, and therefore was
// not inherited from the environment.
wcstring nshlvl_str = L"1";