config: add support for appending a 'spawn' argument to key bindings

A key binding may now have an optional ':<cmd>' string appended to the
key.

This is intended to be used like so:

  pipe-scrollback:sh -c "cat > file"=Print

TODO: we still only allow one *action*. Meaning you still cannot
specify multiple pipe-scrollback bindings, for example.
This commit is contained in:
Daniel Eklöf 2020-07-15 13:32:31 +02:00
parent f21ea97037
commit 57f5cc1bf2
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 18 additions and 3 deletions

View file

@ -530,11 +530,20 @@ parse_section_key_bindings(
const char *key, const char *value, struct config *conf,
const char *path, unsigned lineno)
{
for (enum bind_action_normal action = 0; action < BIND_ACTION_COUNT; action++) {
const char *spawn = strchr(key, ':');
if (spawn != NULL)
spawn++;
const size_t key_len = spawn != NULL ? spawn - key - 1: strlen(key);
for (enum bind_action_normal action = 0;
action < BIND_ACTION_COUNT;
action++)
{
if (binding_action_map[action] == NULL)
continue;
if (strcmp(key, binding_action_map[action]) != 0)
if (strncmp(key, binding_action_map[action], key_len) != 0)
continue;
if (strcasecmp(value, "none") == 0) {
@ -548,7 +557,9 @@ parse_section_key_bindings(
}
free(conf->bindings.key[action]);
free(conf->bindings.spawn[action]);
conf->bindings.key[action] = strdup(value);
conf->bindings.spawn[action] = spawn != NULL ? strdup(spawn) : NULL;
return true;
}
@ -984,8 +995,10 @@ config_free(struct config conf)
tll_free(conf.fonts);
free(conf.server_socket_path);
for (enum bind_action_normal i = 0; i < BIND_ACTION_COUNT; i++)
for (enum bind_action_normal i = 0; i < BIND_ACTION_COUNT; i++) {
free(conf.bindings.key[i]);
free(conf.bindings.spawn[i]);
}
for (enum bind_action_search i = 0; i < BIND_ACTION_SEARCH_COUNT; i++)
free(conf.bindings.search[i]);
}

View file

@ -49,6 +49,8 @@ struct config {
struct {
/* Bindings for "normal" mode */
char *key[BIND_ACTION_COUNT];
char *spawn[BIND_ACTION_COUNT];
struct mouse_binding mouse[BIND_ACTION_COUNT];
/*