cmdtree

A trie command launcher for X11
git clone git://jb55.com/cmdtree
Log | Files | Refs | README | LICENSE

commit d2ce420ae24cbdd2c61f38342bdabc19c2358947
parent 22e403ca533419e1d19bf5c4dad8b2bbc4eb2173
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  9 Jul 2018 17:43:46 -0700

it works yo

Diffstat:
Mcmdtree.c | 5+++--
Mcommand.c | 11+++++++++--
Mcommand.h | 3+++
3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/cmdtree.c b/cmdtree.c @@ -292,8 +292,9 @@ run(Drw *drw) { rootcmds = cmd->children; draw_tree(drw, 0, 0, mw, mh); } - else // TODO: launch command - done = 1; + else { + command_exec(cmd); + } } break; diff --git a/command.c b/command.c @@ -4,6 +4,8 @@ #include "ccan/tal/tal.h" #include "ccan/tal/str/str.h" #include "ccan/str/str.h" +#include <err.h> +#include <unistd.h> #include "util.h" @@ -18,6 +20,11 @@ command_is_prefix(struct command *cmd) { return count > 0; } +void +command_exec(struct command *cmd) { + execlp(cmd->name, cmd->name, (char *)NULL); + err(1, "executing command %s", cmd->name); +} struct command * command_lookup(struct command *cmd, const char *binding) { @@ -33,7 +40,7 @@ command_lookup(struct command *cmd, const char *binding) { static const struct command examples[] = { { .bind = "f", .name = "firefox" }, { .bind = "m", .name = "misc" }, - { .bind = "e", .name = "spacemacs" }, + { .bind = "e", .name = "emacs" }, { .bind = "N", .name = "networking" }, }; @@ -57,7 +64,7 @@ test_root_commands(tal_t *ctx) { } child = cmds[i].children = tal_arr(cmds, struct command, i % 2); for (j = 0; j < tal_count(child); j++) { - child[j].name = tal_fmt(child, "child-%d-%d", (int)i, (int)j); + child[j].name = "sayhi"; child[j].bind = tal_fmt(child, "%c", (int)(c+j)); child[j].children = NULL; } diff --git a/command.h b/command.h @@ -15,6 +15,9 @@ struct command { void command_init(struct command *cmd); +void +command_exec(struct command *cmd); + struct command * command_lookup(struct command *cmd, const char *binding);