diff --git a/src/event.cpp b/src/event.cpp index 8fa64a025..50341862d 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -517,6 +517,16 @@ event_t event_t::variable(wcstring name, wcstring_list_t args) { return evt; } +// static +event_t event_t::variable_erase(wcstring name) { + return event_t::variable(name, {L"VARIABLE", L"ERASE", name}); +} + +// static +event_t event_t::variable_set(wcstring name) { + return event_t::variable(name, {L"VARIABLE", L"SET", name}); +} + // static event_t event_t::process_exit(pid_t pid, int status) { event_t evt{event_type_t::process_exit}; diff --git a/src/event.h b/src/event.h index 52049059e..4fcfe2621 100644 --- a/src/event.h +++ b/src/event.h @@ -107,6 +107,10 @@ struct event_t { /// Create an event_type_t::variable event. static event_t variable(wcstring name, wcstring_list_t args); + /// Create an event_type_t::variable event with the args for erasing a variable. + static event_t variable_erase(wcstring name); + /// Create an event_type_t::variable event with the args for setting a variable. + static event_t variable_set(wcstring name); /// Create a PROCESS_EXIT event. static event_t process_exit(pid_t pid, int status); diff --git a/src/parser.cpp b/src/parser.cpp index d61e6f00a..91373eaca 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -102,10 +102,9 @@ parser_t &parser_t::principal_parser() { } int parser_t::set_var_and_fire(const wcstring &key, env_mode_flags_t mode, wcstring_list_t vals) { - std::vector events; - int res = vars().set(key, mode, std::move(vals), &events); - for (const auto &evt : events) { - event_fire(*this, evt); + int res = vars().set(key, mode, std::move(vals), nullptr); + if (res == ENV_OK) { + event_fire(*this, event_t::variable_set(key)); } return res; }