From 8a60b03a0119c5ae071952dd5915f2741b3fe4f2 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 9 Jul 2018 20:05:58 -0700 Subject: allow name to be different from command --- cfg.def.h | 7 ++++--- cmdtree.c | 1 - command.c | 3 ++- command.h | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cfg.def.h b/cfg.def.h index ad2c9cd..0ddbb5d 100644 --- a/cfg.def.h +++ b/cfg.def.h @@ -45,7 +45,7 @@ static struct command browser_commands[] = { { .bind = "f", .name = "firefox", .nchildren = 0, .children = NULL }, }; -static const struct command commands[] = { +static struct command commands[] = { { .bind = "b", .name = "browsers", .nchildren = LENGTH(browser_commands), @@ -53,8 +53,9 @@ static const struct command commands[] = { }, { .bind = "e", - .name = "emacs-dev", - .children = NULL, + .name = "emacs", + .command = "emacs-dev", + .children = 0, .nchildren = 0 }, }; diff --git a/cmdtree.c b/cmdtree.c index be8dcb5..d52920f 100644 --- a/cmdtree.c +++ b/cmdtree.c @@ -41,7 +41,6 @@ static XIC xic; #include "cfg.h" - static int cmdstack_push_(struct command *children, int nchildren) { if (cmdstack_ptr + 1 >= CMDSTACK_SIZE) diff --git a/command.c b/command.c index 9701408..2f81eaa 100644 --- a/command.c +++ b/command.c @@ -17,7 +17,8 @@ command_is_prefix(struct command *cmd) { void command_exec(struct command *cmd) { - execlp("/bin/sh", "sh", "-c", cmd->name, (char *) 0); + const char *cmdname = cmd->command == NULL ? cmd->name : cmd->command; + execlp("/bin/sh", "sh", "-c", cmdname, (char *) 0); err(1, "executing command %s", cmd->name); } diff --git a/command.h b/command.h index 70fc426..d4f93fb 100644 --- a/command.h +++ b/command.h @@ -6,6 +6,7 @@ struct command { char *name; + char *command; char *bind; struct command *children; int nchildren; -- cgit v1.2.3