summaryrefslogtreecommitdiff
path: root/Userland/Shell/Shell.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-05-11 11:42:36 +0430
committerLinus Groh <mail@linusgroh.de>2021-05-11 10:19:07 +0100
commita5272563567346ef1085d55c63934f41360d6784 (patch)
tree122dcb50272640902a8bbf537fc7b474ba537c65 /Userland/Shell/Shell.cpp
parent4d01183f5c6df152b5c68def74da4d4189c0dbc8 (diff)
downloadserenity-a5272563567346ef1085d55c63934f41360d6784.zip
Shell: Add an option to autosave history every N ms
...and set it to 10 seconds by default.
Diffstat (limited to 'Userland/Shell/Shell.cpp')
-rw-r--r--Userland/Shell/Shell.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp
index 0dc3caae62..8737d8c3c7 100644
--- a/Userland/Shell/Shell.cpp
+++ b/Userland/Shell/Shell.cpp
@@ -1844,6 +1844,8 @@ Shell::Shell(Line::Editor& editor, bool attempt_interactive)
return EDITOR_INTERNAL_FUNCTION(finish)(editor);
});
+
+ start_timer(3000);
}
Shell::~Shell()
@@ -2056,6 +2058,36 @@ Optional<int> Shell::resolve_job_spec(const String& str)
return {};
}
+void Shell::timer_event(Core::TimerEvent& event)
+{
+ event.accept();
+
+ if (m_is_subshell)
+ return;
+
+ StringView option = getenv("HISTORY_AUTOSAVE_TIME_MS");
+
+ auto time = option.to_uint();
+ if (!time.has_value() || time.value() == 0) {
+ m_history_autosave_time.clear();
+ stop_timer();
+ start_timer(3000);
+ return;
+ }
+
+ if (m_history_autosave_time != time) {
+ m_history_autosave_time = time.value();
+ stop_timer();
+ start_timer(m_history_autosave_time.value());
+ }
+
+ if (!m_history_autosave_time.has_value())
+ return;
+
+ if (m_editor)
+ m_editor->save_history(get_history_path());
+}
+
void FileDescriptionCollector::collect()
{
for (auto fd : m_fds)