From 47a38b57b48d0127030e2c7e2f1fc855d74fd87a Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 9 Jul 2018 16:32:18 -0700 Subject: wip --- README | 15 --------------- README.md | 17 +++++++++++++++++ cmdtree.c | 1 + command.c | 20 +++++++++++++++++--- 4 files changed, 35 insertions(+), 18 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 76da7fa..0000000 --- a/README +++ /dev/null @@ -1,15 +0,0 @@ - -cmdtree -======= - -cmdtree is a command launcher in the form of a trie. Commands are launched by a -sequence of keys that form a path in this trie. - -Configuring cmdtree is easy (this format is still WIP): - -~/.cmdtreerc or ~/.config/cmdtree/cmdtreerc: - -(a application - (b chrome --force-device-scale-factor=1.25) - (e emacs) -) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e11da60 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ + +cmdtree +======= + +![cmdtree](https://jb55.com/s/cmdtree.png) + +cmdtree is a command launcher in the form of a trie. Commands are launched by a +sequence of keys that form a path in this trie. + +Configuring cmdtree is easy (this format is still WIP): + +`~/.cmdtreerc` or `~/.config/cmdtree/cmdtreerc`: + + (a application + (b chrome --force-device-scale-factor=1.25) + (e emacs) + ) diff --git a/cmdtree.c b/cmdtree.c index 21c0bd3..5ba5595 100644 --- a/cmdtree.c +++ b/cmdtree.c @@ -257,6 +257,7 @@ draw_tree(Drw *drw, int x, int y, int w, int h) { static void cleanup(Drw *drw, int code) { drw_free(drw); + tal_free(rootcmds); exit(0); } diff --git a/command.c b/command.c index a4b4e55..64cce58 100644 --- a/command.c +++ b/command.c @@ -4,6 +4,8 @@ #include "ccan/tal/tal.h" #include "ccan/tal/str/str.h" +#include "util.h" + void command_init(struct command *cmd) { cmd->children = NULL; @@ -15,6 +17,12 @@ command_is_prefix(struct command *cmd) { return count > 0; } +static const struct command examples[] = { + { .bind = "f", .name = "firefox" }, + { .bind = "m", .name = "misc" }, + { .bind = "e", .name = "spacemacs" }, + { .bind = "N", .name = "networking" }, +}; struct command * test_root_commands(tal_t *ctx) { @@ -22,12 +30,18 @@ test_root_commands(tal_t *ctx) { struct command *cmds = NULL; struct command *child = NULL; - cmds = tal_arr(ctx, struct command, 5); + cmds = tal_arr(ctx, struct command, 10); const unsigned long c = 'a'; for (i = 0; i < tal_count(cmds); i++) { - cmds[i].name = tal_fmt(cmds, "hello-%d", (int)i); - cmds[i].bind = tal_fmt(cmds, "%c", (int)(c+i)); + if (i < LENGTH(examples)) { + cmds[i].name = examples[i].name; + cmds[i].bind = examples[i].bind; + } + else { + cmds[i].name = tal_fmt(cmds, "example-%d", (int)i); + cmds[i].bind = tal_fmt(cmds, "%c", (int)(c+i)); + } 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); -- cgit v1.2.3