summaryrefslogtreecommitdiffstats
path: root/cmd-bind-key.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2013-03-22 15:52:40 +0000
committerNicholas Marriott <nicm@openbsd.org>2013-03-22 15:52:40 +0000
commit58932295fcd80062569e808897e9e1d252ec888a (patch)
treebd1865707d9b377bd010ce3185ee0347200e6c71 /cmd-bind-key.c
parent8478895eeb014a4219c4d61edd598c05b073db68 (diff)
Add copy-pipe mode command to copy selection and also pipe to a command.
Diffstat (limited to 'cmd-bind-key.c')
-rw-r--r--cmd-bind-key.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index 909f4839..086ac4ec 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -46,7 +46,7 @@ enum cmd_retval
cmd_bind_key_check(struct args *args)
{
if (args_has(args, 't')) {
- if (args->argc != 2)
+ if (args->argc != 2 && args->argc != 3)
return (CMD_RETURN_ERROR);
} else {
if (args->argc < 2)
@@ -93,6 +93,7 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
const struct mode_key_table *mtab;
struct mode_key_binding *mbind, mtmp;
enum mode_key_cmd cmd;
+ const char *arg;
tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) {
@@ -106,16 +107,29 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
return (CMD_RETURN_ERROR);
}
+ if (cmd != MODEKEYCOPY_COPYPIPE) {
+ if (args->argc != 2) {
+ ctx->error(ctx, "no argument allowed");
+ return (CMD_RETURN_ERROR);
+ }
+ arg = NULL;
+ } else {
+ if (args->argc != 3) {
+ ctx->error(ctx, "no argument given");
+ return (CMD_RETURN_ERROR);
+ }
+ arg = args->argv[2];
+ }
+
mtmp.key = key;
mtmp.mode = !!args_has(args, 'c');
- if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
- mbind->cmd = cmd;
- return (CMD_RETURN_NORMAL);
+ if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
+ mbind = xmalloc(sizeof *mbind);
+ mbind->key = mtmp.key;
+ mbind->mode = mtmp.mode;
+ RB_INSERT(mode_key_tree, mtab->tree, mbind);
}
- mbind = xmalloc(sizeof *mbind);
- mbind->key = mtmp.key;
- mbind->mode = mtmp.mode;
mbind->cmd = cmd;
- RB_INSERT(mode_key_tree, mtab->tree, mbind);
+ mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
return (CMD_RETURN_NORMAL);
}