From 30ad9a04759bc85931446cd8f4594ea71db22985 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 6 Sep 2015 18:09:32 +0100 Subject: [PATCH] Complete aliases in command prompt --- src/alias_registry.hh | 5 +++++ src/command_manager.cc | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/alias_registry.hh b/src/alias_registry.hh index 4f1a472b..faf856d6 100644 --- a/src/alias_registry.hh +++ b/src/alias_registry.hh @@ -16,6 +16,11 @@ public: void remove_alias(const String& alias); StringView operator[](const String& name) const; + using AliasMap = UnorderedMap; + using iterator = AliasMap::const_iterator; + iterator begin() const { return m_aliases.begin(); } + iterator end() const { return m_aliases.end(); } + Vector aliases_for(StringView command) const; private: diff --git a/src/command_manager.cc b/src/command_manager.cc index e626ed6c..5d5920a2 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -567,9 +567,14 @@ Completions CommandManager::complete(const Context& context, { if (command.second.flags & CommandFlags::Hidden) continue; - if ( prefix_match(command.first, prefix)) + if (prefix_match(command.first, prefix)) result.candidates.push_back(command.first); } + for (auto& alias : context.aliases()) + { + if (prefix_match(alias.first, prefix)) + result.candidates.push_back(alias.first); + } std::sort(result.candidates.begin(), result.candidates.end()); return result; }