summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd-bind-key.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2013-03-22 15:52:40 +0000
committernicm <nicm@openbsd.org>2013-03-22 15:52:40 +0000
commit94d83468da0ca9948bdfb09670093a495fa9e7ed (patch)
treef252d7f24998089dd08e49d99870325351edefed /usr.bin/tmux/cmd-bind-key.c
parentAdd -e flag to capture-pane to include embedded ANSI SGR escape (diff)
downloadwireguard-openbsd-94d83468da0ca9948bdfb09670093a495fa9e7ed.tar.xz
wireguard-openbsd-94d83468da0ca9948bdfb09670093a495fa9e7ed.zip
Add copy-pipe mode command to copy selection and also pipe to a command.
Diffstat (limited to 'usr.bin/tmux/cmd-bind-key.c')
-rw-r--r--usr.bin/tmux/cmd-bind-key.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/usr.bin/tmux/cmd-bind-key.c b/usr.bin/tmux/cmd-bind-key.c
index 42a45fbf90f..54291a7a9f6 100644
--- a/usr.bin/tmux/cmd-bind-key.c
+++ b/usr.bin/tmux/cmd-bind-key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-bind-key.c,v 1.14 2012/07/11 07:10:15 nicm Exp $ */
+/* $OpenBSD: cmd-bind-key.c,v 1.15 2013/03/22 15:52:40 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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);
}