Skip to content

Commit 0d88f8a

Browse files
author
nicm
committed
Add an "Any" key to run a command if a key is pressed that is not bound
in the current key table. GitHub issue 1404.
1 parent ff67ef9 commit 0d88f8a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

key-string.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,11 @@ key_string_lookup_string(const char *string)
166166
enum utf8_state more;
167167
wchar_t wc;
168168

169-
/* Is this no key? */
169+
/* Is this no key or any key? */
170170
if (strcasecmp(string, "None") == 0)
171171
return (KEYC_NONE);
172+
if (strcasecmp(string, "Any") == 0)
173+
return (KEYC_ANY);
172174

173175
/* Is this a hexadecimal value? */
174176
if (string[0] == '0' && string[1] == 'x') {
@@ -251,6 +253,8 @@ key_string_lookup_key(key_code key)
251253
/* Handle special keys. */
252254
if (key == KEYC_UNKNOWN)
253255
return ("Unknown");
256+
if (key == KEYC_ANY)
257+
return ("Any");
254258
if (key == KEYC_FOCUS_IN)
255259
return ("FocusIn");
256260
if (key == KEYC_FOCUS_OUT)

server-client.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ server_client_handle_key(struct client *c, key_code key)
907907
* The prefix always takes precedence and forces a switch to the prefix
908908
* table, unless we are already there.
909909
*/
910-
retry:
911910
key0 = (key & ~KEYC_XTERM);
911+
retry:
912912
if ((key0 == (key_code)options_get_number(s->options, "prefix") ||
913913
key0 == (key_code)options_get_number(s->options, "prefix2")) &&
914914
strcmp(table->name, "prefix") != 0) {
@@ -980,6 +980,10 @@ server_client_handle_key(struct client *c, key_code key)
980980
* switch the client back to the root table and try again.
981981
*/
982982
log_debug("not found in key table %s", table->name);
983+
if (key0 != KEYC_ANY) {
984+
key0 = KEYC_ANY;
985+
goto retry;
986+
}
983987
if (!server_client_is_default_key_table(c, table) ||
984988
(c->flags & CLIENT_REPEAT)) {
985989
server_client_set_key_table(c, NULL);

tmux.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ enum {
136136
KEYC_FOCUS_IN = KEYC_BASE,
137137
KEYC_FOCUS_OUT,
138138

139+
/* "Any" key, used if not found in key table. */
140+
KEYC_ANY,
141+
139142
/* Paste brackets. */
140143
KEYC_PASTE_START,
141144
KEYC_PASTE_END,

0 commit comments

Comments
 (0)