Flag to flush all key bindings from Rob Paisley.

This commit is contained in:
Nicholas Marriott 2010-11-11 20:54:06 +00:00
parent c7fccfa299
commit 17b56562c4
2 changed files with 35 additions and 12 deletions

View File

@ -33,13 +33,14 @@ int cmd_unbind_key_table(struct cmd *, struct cmd_ctx *);
struct cmd_unbind_key_data { struct cmd_unbind_key_data {
int key; int key;
int flag_all;
int command_key; int command_key;
char *tablename; char *tablename;
}; };
const struct cmd_entry cmd_unbind_key_entry = { const struct cmd_entry cmd_unbind_key_entry = {
"unbind-key", "unbind", "unbind-key", "unbind",
"[-cn] [-t key-table] key", "[-acn] [-t key-table] key",
0, "", 0, "",
NULL, NULL,
cmd_unbind_key_parse, cmd_unbind_key_parse,
@ -55,11 +56,15 @@ cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
int opt, no_prefix = 0; int opt, no_prefix = 0;
self->data = data = xmalloc(sizeof *data); self->data = data = xmalloc(sizeof *data);
data->flag_all = 0;
data->command_key = 0; data->command_key = 0;
data->tablename = NULL; data->tablename = NULL;
while ((opt = getopt(argc, argv, "cnt:")) != -1) { while ((opt = getopt(argc, argv, "acnt:")) != -1) {
switch (opt) { switch (opt) {
case 'a':
data->flag_all = 1;
break;
case 'c': case 'c':
data->command_key = 1; data->command_key = 1;
break; break;
@ -76,15 +81,20 @@ cmd_unbind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc != 1) if (data->flag_all && (argc != 0 || data->tablename))
goto usage;
if (!data->flag_all && argc != 1)
goto usage; goto usage;
if ((data->key = key_string_lookup_string(argv[0])) == KEYC_NONE) { if (!data->flag_all) {
data->key = key_string_lookup_string(argv[0]);
if (data->key == KEYC_NONE) {
xasprintf(cause, "unknown key: %s", argv[0]); xasprintf(cause, "unknown key: %s", argv[0]);
goto error; goto error;
} }
if (!no_prefix) if (!no_prefix)
data->key |= KEYC_PREFIX; data->key |= KEYC_PREFIX;
}
return (0); return (0);
@ -100,13 +110,23 @@ int
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx) cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
{ {
struct cmd_unbind_key_data *data = self->data; struct cmd_unbind_key_data *data = self->data;
struct key_binding *bd;
if (data == NULL) if (data == NULL)
return (0); return (0);
if (data->flag_all) {
while (!SPLAY_EMPTY(&key_bindings)) {
bd = SPLAY_ROOT(&key_bindings);
SPLAY_REMOVE(key_bindings, &key_bindings, bd);
cmd_list_free(bd->cmdlist);
xfree(bd);
}
} else {
if (data->tablename != NULL) if (data->tablename != NULL)
return (cmd_unbind_key_table(self, ctx)); return (cmd_unbind_key_table(self, ctx));
key_bindings_remove(data->key); key_bindings_remove(data->key);
}
return (0); return (0);
} }

5
tmux.1
View File

@ -1479,7 +1479,7 @@ All arguments are sent sequentially from first to last.
Send the prefix key to a window as if it was pressed. Send the prefix key to a window as if it was pressed.
If multiple prefix keys are configured, only the first is sent. If multiple prefix keys are configured, only the first is sent.
.It Xo Ic unbind-key .It Xo Ic unbind-key
.Op Fl cn .Op Fl acn
.Op Fl t Ar key-table .Op Fl t Ar key-table
.Ar key .Ar key
.Xc .Xc
@ -1493,6 +1493,9 @@ the primary key bindings are modified; in this case, if
is specified, the command bound to is specified, the command bound to
.Ar key .Ar key
without a prefix (if any) is removed. without a prefix (if any) is removed.
If
.Fl a
is present, all key bindings are removed.
.Pp .Pp
If If
.Fl t .Fl t