diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-25 12:18:52 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-08-25 12:18:52 +0000 |
commit | 3b82430ff83eff28d489555fa5840fb1e0735d19 (patch) | |
tree | 01b26d1875690d638c182ba7dfd45ad8fe59522b /usr.bin/tmux/cmd-command-prompt.c | |
parent | 3a2cf682677a24dc0f66604f7d0701f10275a58b (diff) |
Add a choose-client command and extend choose-{session,window} to accept a
template. After a choice is made, %% (or %1) in the template is replaced by the
name of the session, window or client suitable for -t and the result executed
as a command. So, for example, "choose-window "killw -t '%%'"" will kill the
selected window.
The defaults if no template is given are (as now) select-window for
choose-window, switch-client for choose-session, and detach-client for
choose-client (now bound to D).
Diffstat (limited to 'usr.bin/tmux/cmd-command-prompt.c')
-rw-r--r-- | usr.bin/tmux/cmd-command-prompt.c | 45 |
1 files changed, 2 insertions, 43 deletions
diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c index bc65e877937..df4ef5e9997 100644 --- a/usr.bin/tmux/cmd-command-prompt.c +++ b/usr.bin/tmux/cmd-command-prompt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-command-prompt.c,v 1.9 2009/08/23 16:45:00 nicm Exp $ */ +/* $OpenBSD: cmd-command-prompt.c,v 1.10 2009/08/25 12:18:51 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -35,7 +35,6 @@ size_t cmd_command_prompt_print(struct cmd *, char *, size_t); int cmd_command_prompt_callback(void *, const char *); void cmd_command_prompt_cfree(void *); -char *cmd_command_prompt_replace(char *, const char *, int); const struct cmd_entry cmd_command_prompt_entry = { "command-prompt", NULL, @@ -216,7 +215,7 @@ cmd_command_prompt_callback(void *data, const char *s) if (s == NULL) return (0); - newtempl = cmd_command_prompt_replace(cdata->template, s, cdata->idx); + newtempl = cmd_template_replace(cdata->template, s, cdata->idx); xfree(cdata->template); cdata->template = newtempl; @@ -265,43 +264,3 @@ cmd_command_prompt_cfree(void *data) xfree(cdata->template); xfree(cdata); } - -char * -cmd_command_prompt_replace(char *template, const char *s, int idx) -{ - char ch; - char *buf, *ptr; - int replaced; - size_t len; - - if (strstr(template, "%") == NULL) - return (xstrdup(template)); - - buf = xmalloc(1); - *buf = '\0'; - len = 0; - replaced = 0; - - ptr = template; - while (*ptr != '\0') { - switch (ch = *ptr++) { - case '%': - if (*ptr < '1' || *ptr > '9' || *ptr - '0' != idx) { - if (*ptr != '%' || replaced) - break; - replaced = 1; - } - ptr++; - - len += strlen(s); - buf = xrealloc(buf, 1, len + 1); - strlcat(buf, s, len + 1); - continue; - } - buf = xrealloc(buf, 1, len + 2); - buf[len++] = ch; - buf[len] = '\0'; - } - - return (buf); -} |