zcmdcat: zsh completion: group commands by category

This commit is contained in:
Daniel Shahaf 2015-07-20 05:31:36 +00:00 committed by Paul Beckingham
parent 5ca1dd540e
commit c78fc47402
4 changed files with 59 additions and 10 deletions

View file

@ -80,18 +80,22 @@ CmdZshCommands::CmdZshCommands ()
////////////////////////////////////////////////////////////////////////////////
int CmdZshCommands::execute (std::string& output)
{
// Get a list of all commands.
std::vector <std::string> commands;
// Get a list of all command descriptions, sorted by category and then
// alphabetically by command name.
typedef std::tuple <Command::Category, std::string, std::string> Element;
std::vector <Element> commands;
for (auto& command : context.commands)
commands.push_back (command.first);
// Sort alphabetically.
commands.push_back (std::make_tuple (command.second->_category,
command.first,
command.second->description()));
std::sort (commands.begin (), commands.end ());
// Emit the commands in order.
std::stringstream out;
for (auto& c : commands)
out << c << ":" << context.commands[c]->description () << "\n";
out << std::get<1> (c) << ":"
<< Command::categoryNames.at (std::get<0> (c)) << ":"
<< std::get<2> (c) << "\n";
output = out.str ();
return 0;

View file

@ -50,6 +50,7 @@ public:
enum class Category
{
unassigned,
// In presentation ("usefulness") order: frequently-used categories first.
interrogator,
report,
operation,