4 * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
26 * Unbind key from command.
29 static enum cmd_retval
cmd_unbind_key_exec(struct cmd
*, struct cmdq_item
*);
31 const struct cmd_entry cmd_unbind_key_entry
= {
35 .args
= { "anqT:", 0, 1, NULL
},
36 .usage
= "[-anq] [-T key-table] key",
38 .flags
= CMD_AFTERHOOK
,
39 .exec
= cmd_unbind_key_exec
42 static enum cmd_retval
43 cmd_unbind_key_exec(struct cmd
*self
, struct cmdq_item
*item
)
45 struct args
*args
= cmd_get_args(self
);
47 const char *tablename
, *keystr
= args_string(args
, 0);
48 int quiet
= args_has(args
, 'q');
50 if (args_has(args
, 'a')) {
53 cmdq_error(item
, "key given with -a");
54 return (CMD_RETURN_ERROR
);
57 tablename
= args_get(args
, 'T');
58 if (tablename
== NULL
) {
59 if (args_has(args
, 'n'))
64 if (key_bindings_get_table(tablename
, 0) == NULL
) {
66 cmdq_error(item
, "table %s doesn't exist" ,
69 return (CMD_RETURN_ERROR
);
72 key_bindings_remove_table(tablename
);
73 return (CMD_RETURN_NORMAL
);
78 cmdq_error(item
, "missing key");
79 return (CMD_RETURN_ERROR
);
82 key
= key_string_lookup_string(keystr
);
83 if (key
== KEYC_NONE
|| key
== KEYC_UNKNOWN
) {
85 cmdq_error(item
, "unknown key: %s", keystr
);
86 return (CMD_RETURN_ERROR
);
89 if (args_has(args
, 'T')) {
90 tablename
= args_get(args
, 'T');
91 if (key_bindings_get_table(tablename
, 0) == NULL
) {
93 cmdq_error(item
, "table %s doesn't exist" ,
96 return (CMD_RETURN_ERROR
);
98 } else if (args_has(args
, 'n'))
101 tablename
= "prefix";
102 key_bindings_remove(tablename
, key
);
103 return (CMD_RETURN_NORMAL
);