diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-03-23 01:14:48 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-03-26 21:34:56 +0430 |
commit | 7e4cc187d9801ef9d37ad7effdb9649c62a55524 (patch) | |
tree | a0de4b779292f0a81a01b07d0f49cbd645ab4de7 /Userland/Shell/AST.h | |
parent | fc4d36ccd03dcb083287ac093f4cd0e06b6a0a9d (diff) | |
download | serenity-7e4cc187d9801ef9d37ad7effdb9649c62a55524.zip |
Shell: Implement program-aware autocompletion
A program can either respond to `--complete -- some args to complete`
directly, or add a `_complete_<program name>` invokable (i.e. shell
function, or just a plain binary in PATH) that completes the given
command and lists the completions on stdout.
Should such a completion fail or yield no results, we'll fall back to
the previous completion algorithm.
Diffstat (limited to 'Userland/Shell/AST.h')
-rw-r--r-- | Userland/Shell/AST.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Userland/Shell/AST.h b/Userland/Shell/AST.h index 7e9abeec8f..85ab950896 100644 --- a/Userland/Shell/AST.h +++ b/Userland/Shell/AST.h @@ -217,6 +217,7 @@ struct HitTestResult { class Value : public RefCounted<Value> { public: virtual Vector<String> resolve_as_list(RefPtr<Shell>) = 0; + virtual String resolve_as_string(RefPtr<Shell> shell); virtual Vector<Command> resolve_as_commands(RefPtr<Shell>); virtual NonnullRefPtr<Value> resolve_without_cast(RefPtr<Shell>) { return *this; } virtual NonnullRefPtr<Value> clone() const = 0; @@ -279,6 +280,7 @@ private: class JobValue final : public Value { public: virtual Vector<String> resolve_as_list(RefPtr<Shell>) override { VERIFY_NOT_REACHED(); } + virtual String resolve_as_string(RefPtr<Shell>) override { return String::formatted("%{}", m_job->job_id()); } virtual Vector<Command> resolve_as_commands(RefPtr<Shell>) override { VERIFY_NOT_REACHED(); } virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<JobValue>(m_job)->set_slices(m_slices); } virtual ~JobValue(); @@ -322,6 +324,7 @@ private: class StringValue final : public Value { public: virtual Vector<String> resolve_as_list(RefPtr<Shell>) override; + virtual String resolve_as_string(RefPtr<Shell> shell) override; virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<StringValue>(m_string, m_split, m_keep_empty)->set_slices(m_slices); } virtual ~StringValue(); virtual bool is_string() const override { return m_split.is_null(); } @@ -360,6 +363,7 @@ private: class SimpleVariableValue final : public Value { public: virtual Vector<String> resolve_as_list(RefPtr<Shell>) override; + virtual String resolve_as_string(RefPtr<Shell>) override; virtual NonnullRefPtr<Value> resolve_without_cast(RefPtr<Shell>) override; virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<SimpleVariableValue>(m_name)->set_slices(m_slices); } virtual ~SimpleVariableValue(); @@ -375,6 +379,7 @@ private: class SpecialVariableValue final : public Value { public: virtual Vector<String> resolve_as_list(RefPtr<Shell>) override; + virtual String resolve_as_string(RefPtr<Shell>) override; virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<SpecialVariableValue>(m_name)->set_slices(m_slices); } virtual ~SpecialVariableValue(); SpecialVariableValue(char name) @@ -389,6 +394,7 @@ private: class TildeValue final : public Value { public: virtual Vector<String> resolve_as_list(RefPtr<Shell>) override; + virtual String resolve_as_string(RefPtr<Shell>) override; virtual NonnullRefPtr<Value> clone() const override { return make_ref_counted<TildeValue>(m_username)->set_slices(m_slices); } virtual ~TildeValue(); virtual bool is_string() const override { return true; } |