Set $fish_private_mode and show a message on private mode startup

The message can be localized and is set as a global variable shadowing
the universally-defined $fish_greeting.
This commit is contained in:
Mahmoud Al-Qudsi 2018-10-21 21:18:27 -05:00 committed by Fabian Homborg
parent 379f44fabe
commit ebb3a3a16e
3 changed files with 8 additions and 1 deletions

View file

@ -36,6 +36,11 @@ function __fish_config_interactive -d "Initializations that should be performed
set -U fish_greeting "$line1$line2"
end
if set -q fish_private_mode
set -l line (_ "fish is running in private mode, history will not be persisted.")
set -g fish_greeting $fish_greeting.\n$line
end
#
# If we are starting up for the first time, set various defaults.
#

View file

@ -296,7 +296,8 @@ 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"history", L"status", L"version", L"fish_pid", L"hostname", L"_"};
const string_set_t env_read_only = {L"PWD", L"SHLVL", L"history", L"status", L"version",
L"fish_pid", L"hostname", L"_", L"fish_private_mode"};
return string_set_contains(env_read_only, val) ||
(in_private_mode() && wcscmp(L"fish_history", val) == 0);
}

View file

@ -1992,6 +1992,7 @@ static bool private_mode = false;
void start_private_mode() {
private_mode = true;
env_set_one(L"fish_history", ENV_GLOBAL, L"");
env_set_one(L"fish_private_mode", ENV_GLOBAL, L"1");
}
bool in_private_mode() {