mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
zcmdcat: zsh completion: group commands by category
This commit is contained in:
parent
5ca1dd540e
commit
c78fc47402
4 changed files with 59 additions and 10 deletions
|
@ -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;
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
enum class Category
|
||||
{
|
||||
unassigned,
|
||||
// In presentation ("usefulness") order: frequently-used categories first.
|
||||
interrogator,
|
||||
report,
|
||||
operation,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue