summaryrefslogtreecommitdiff
path: root/Userland/Shell/Shell.cpp
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-05-24 16:50:16 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-05-24 23:26:49 +0430
commitb2ef18d5380076916f12f1f6a69cf47772b38f3a (patch)
tree1e31e67ac43d3e1757b2482bb2495e28fa799796 /Userland/Shell/Shell.cpp
parente318f12263f571016aa7663f54f9acfb89f7254f (diff)
downloadserenity-b2ef18d5380076916f12f1f6a69cf47772b38f3a.zip
LibLine+Shell: Allow some programs to modify the current termios
This setting can be controlled by setting the PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS _local_ shell variable to a list containing such programs.
Diffstat (limited to 'Userland/Shell/Shell.cpp')
-rw-r--r--Userland/Shell/Shell.cpp25
1 files changed, 22 insertions, 3 deletions
diff --git a/Userland/Shell/Shell.cpp b/Userland/Shell/Shell.cpp
index 76ee97c122..ccec9725c9 100644
--- a/Userland/Shell/Shell.cpp
+++ b/Userland/Shell/Shell.cpp
@@ -342,7 +342,7 @@ Shell::LocalFrame* Shell::find_frame_containing_local_variable(const String& nam
return nullptr;
}
-RefPtr<AST::Value> Shell::lookup_local_variable(const String& name)
+RefPtr<AST::Value> Shell::lookup_local_variable(const String& name) const
{
if (auto* frame = find_frame_containing_local_variable(name))
return frame->local_variables.get(name).value();
@@ -353,7 +353,7 @@ RefPtr<AST::Value> Shell::lookup_local_variable(const String& name)
return nullptr;
}
-RefPtr<AST::Value> Shell::get_argument(size_t index)
+RefPtr<AST::Value> Shell::get_argument(size_t index) const
{
if (index == 0)
return adopt_ref(*new AST::StringValue(current_script));
@@ -377,7 +377,7 @@ RefPtr<AST::Value> Shell::get_argument(size_t index)
return nullptr;
}
-String Shell::local_variable_or(const String& name, const String& replacement)
+String Shell::local_variable_or(const String& name, const String& replacement) const
{
auto value = lookup_local_variable(name);
if (value) {
@@ -846,6 +846,12 @@ RefPtr<Job> Shell::run_command(const AST::Command& command)
last_return_code = job->exit_code();
job->disown();
+ if (m_editor && job->exit_code() == 0 && is_allowed_to_modify_termios(job->command())) {
+ m_editor->refetch_default_termios();
+ default_termios = m_editor->default_termios();
+ termios = m_editor->termios();
+ }
+
run_tail(job);
};
@@ -1025,6 +1031,19 @@ bool Shell::run_file(const String& filename, bool explicitly_invoked)
auto data = file->read_all();
return run_command(data) == 0;
}
+
+bool Shell::is_allowed_to_modify_termios(const AST::Command& command) const
+{
+ if (command.argv.is_empty())
+ return false;
+
+ auto value = lookup_local_variable("PROGRAMS_ALLOWED_TO_MODIFY_DEFAULT_TERMIOS"sv);
+ if (!value)
+ return false;
+
+ return value->resolve_as_list(*this).contains_slow(command.argv[0]);
+}
+
void Shell::restore_ios()
{
if (m_is_subshell)