mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:47:34 +00:00
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.
This commit is contained in:
parent
e318f12263
commit
b2ef18d538
4 changed files with 50 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -108,9 +108,9 @@ public:
|
|||
|
||||
static bool has_history_event(StringView);
|
||||
|
||||
RefPtr<AST::Value> get_argument(size_t);
|
||||
RefPtr<AST::Value> lookup_local_variable(const String&);
|
||||
String local_variable_or(const String&, const String&);
|
||||
RefPtr<AST::Value> get_argument(size_t) const;
|
||||
RefPtr<AST::Value> lookup_local_variable(const String&) const;
|
||||
String local_variable_or(const String&, const String&) const;
|
||||
void set_local_variable(const String&, RefPtr<AST::Value>, bool only_in_current_frame = false);
|
||||
void unset_local_variable(const String&, bool only_in_current_frame = false);
|
||||
|
||||
|
@ -278,6 +278,8 @@ private:
|
|||
|
||||
void timer_event(Core::TimerEvent&) override;
|
||||
|
||||
bool is_allowed_to_modify_termios(const AST::Command&) const;
|
||||
|
||||
// FIXME: Port to Core::Property
|
||||
void save_to(JsonObject&);
|
||||
void bring_cursor_to_beginning_of_a_line() const;
|
||||
|
@ -288,6 +290,10 @@ private:
|
|||
void stop_all_jobs();
|
||||
const Job* m_current_job { nullptr };
|
||||
LocalFrame* find_frame_containing_local_variable(const String& name);
|
||||
const LocalFrame* find_frame_containing_local_variable(const String& name) const
|
||||
{
|
||||
return const_cast<Shell*>(this)->find_frame_containing_local_variable(name);
|
||||
}
|
||||
|
||||
void run_tail(RefPtr<Job>);
|
||||
void run_tail(const AST::Command&, const AST::NodeWithAction&, int head_exit_code);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue