diff --git a/src/command_manager.cc b/src/command_manager.cc index ff4b589a..dafdc11d 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -582,6 +582,11 @@ Completions CommandManager::complete(const Context& context, return offset_pos(shell_complete(context, flags, tokens[tok_idx].content(), cursor_pos_in_token), start); + case Token::Type::ValExpand: + return {start , cursor_pos, + ShellManager::instance().complete_env_var( + tokens[tok_idx].content(), cursor_pos_in_token) }; + case Token::Type::Raw: case Token::Type::RawQuoted: case Token::Type::RawEval: diff --git a/src/shell_manager.cc b/src/shell_manager.cc index 1009d688..d11dc88b 100644 --- a/src/shell_manager.cc +++ b/src/shell_manager.cc @@ -234,4 +234,12 @@ String ShellManager::get_val(StringView name, const Context& context) const return env_var->func(name, context); } +CandidateList ShellManager::complete_env_var(StringView prefix, + ByteCount cursor_pos) const +{ + return complete(prefix, cursor_pos, m_env_vars | + transform([](const EnvVarDesc& desc) -> const String& + { return desc.str; })); +} + } diff --git a/src/shell_manager.hh b/src/shell_manager.hh index b7e462e7..0d9a16a1 100644 --- a/src/shell_manager.hh +++ b/src/shell_manager.hh @@ -6,6 +6,7 @@ #include "flags.hh" #include "string.hh" #include "utils.hh" +#include "completion.hh" namespace Kakoune { @@ -39,6 +40,8 @@ public: void register_env_var(StringView str, bool prefix, EnvVarRetriever retriever); String get_val(StringView name, const Context& context) const; + CandidateList complete_env_var(StringView prefix, ByteCount cursor_pos) const; + private: struct EnvVarDesc { String str; bool prefix; EnvVarRetriever func; }; Vector m_env_vars;