summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-12-02 23:39:03 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-12-02 23:39:03 +0000
commitc083ab86cc5a2949fa6460430aa219401889915b (patch)
tree9e67236641fcf35c7ec6c71a16c22add4d979620
parent54725c3f50962ebc4d84d16a0cbf6bfb701cfb2e (diff)
Add -F to if-shell to allow it to be used to check for format or option
values rather than executing a command.
-rw-r--r--usr.bin/tmux/cmd-if-shell.c29
-rw-r--r--usr.bin/tmux/tmux.115
2 files changed, 37 insertions, 7 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c
index 7a823586005..778d701074b 100644
--- a/usr.bin/tmux/cmd-if-shell.c
+++ b/usr.bin/tmux/cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-if-shell.c,v 1.26 2014/10/20 22:29:25 nicm Exp $ */
+/* $OpenBSD: cmd-if-shell.c,v 1.27 2014/12/02 23:39:02 nicm Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -37,8 +37,8 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
- "bt:", 2, 3,
- "[-b] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
+ "bFt:", 2, 3,
+ "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
0,
cmd_if_shell_exec
};
@@ -56,7 +56,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct cmd_if_shell_data *cdata;
- char *shellcmd;
+ char *shellcmd, *cmd, *cause;
+ struct cmd_list *cmdlist;
struct client *c;
struct session *s = NULL;
struct winlink *wl = NULL;
@@ -84,6 +85,26 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
+ if (args_has(args, 'F')) {
+ cmd = NULL;
+ if (*shellcmd != '0' && *shellcmd != '\0')
+ cmd = args->argv[1];
+ else if (args->argc == 3)
+ cmd = args->argv[2];
+ if (cmd == NULL)
+ return (CMD_RETURN_NORMAL);
+ if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
+ if (cause != NULL) {
+ cmdq_error(cmdq, "%s", cause);
+ free(cause);
+ }
+ return (CMD_RETURN_ERROR);
+ }
+ cmdq_run(cmdq, cmdlist);
+ cmd_list_free(cmdlist);
+ return (CMD_RETURN_NORMAL);
+ }
+
cdata = xmalloc(sizeof *cdata);
cdata->cmd_if = xstrdup(args->argv[1]);
if (args->argc == 3)
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 289353e22d9..649fde05650 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.409 2014/12/02 23:19:45 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.410 2014/12/02 23:39:02 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -3589,7 +3589,7 @@ Miscellaneous commands are as follows:
.It Ic clock-mode Op Fl t Ar target-pane
Display a large clock.
.It Xo Ic if-shell
-.Op Fl b
+.Op Fl bF
.Op Fl t Ar target-pane
.Ar shell-command command
.Op Ar command
@@ -3602,7 +3602,9 @@ if
returns success or the second
.Ar command
otherwise.
-Before being executed, shell-command is expanded using the rules specified in the
+Before being executed,
+.Ar shell-command
+is expanded using the rules specified in the
.Sx FORMATS
section, including those relevant to
.Ar target-pane .
@@ -3610,6 +3612,13 @@ With
.Fl b ,
.Ar shell-command
is run in the background.
+.Pp
+If
+.Fl F
+is given,
+.Ar shell-command
+is not executed but considered success if neither empty nor zero (after formats
+are expanded).
.It Ic lock-server
.D1 (alias: Ic lock )
Lock each client individually by running the command specified by the