From 90d0f91bcd9787ab3b25e5d558f5218901db8cd7 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Fri, 9 Mar 2018 03:47:28 -0600 Subject: [PATCH] Define read-only $pid as %self replacement --- src/env.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/env.cpp b/src/env.cpp index 0928367ab..fc11bcbd5 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -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(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";