aboutsummaryrefslogtreecommitdiff
path: root/cmd-bind-key.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2013-02-19 17:49:53 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2013-02-19 17:49:53 +0000
commitc3859d1df1fbdb63b8aab15d10266e26c5e428eb (patch)
tree8e83d8986670137d3c6e4f54aa1f1dbb92533ae1 /cmd-bind-key.c
parent5a5e285be8caf98c7777a2afa717d04ac44c9f75 (diff)
downloadrtmux-c3859d1df1fbdb63b8aab15d10266e26c5e428eb.tar.gz
rtmux-c3859d1df1fbdb63b8aab15d10266e26c5e428eb.tar.bz2
rtmux-c3859d1df1fbdb63b8aab15d10266e26c5e428eb.zip
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 28e94e26..2a7b482a 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);
}