Sync OpenBSD patchset 972:

Didn't really think the else behaviour through - requiring argv to
contain "else" is silly so just omit that, also some manpage
tweaks. From Tiago Cunha.
This commit is contained in:
Tiago Cunha 2011-10-31 13:55:10 +00:00
parent d8d9c2af98
commit 3f5ec24b5a
2 changed files with 13 additions and 23 deletions

View File

@ -25,10 +25,9 @@
#include "tmux.h" #include "tmux.h"
/* /*
* Executes a tmux command if a shell command returns true. * Executes a tmux command if a shell command returns true or false.
*/ */
int cmd_if_shell_check(struct args *);
int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *); int cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
void cmd_if_shell_callback(struct job *); void cmd_if_shell_callback(struct job *);
@ -36,11 +35,11 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = { const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if", "if-shell", "if",
"", 2, 4, "", 2, 3,
"shell-command command [else command]", "shell-command command [command]",
0, 0,
NULL, NULL,
cmd_if_shell_check, NULL,
cmd_if_shell_exec cmd_if_shell_exec
}; };
@ -50,16 +49,6 @@ struct cmd_if_shell_data {
struct cmd_ctx ctx; struct cmd_ctx ctx;
}; };
int
cmd_if_shell_check(struct args *args)
{
if (args->argc == 3)
return (-1);
if (args->argc == 4 && strcmp(args->argv[2], "else") != 0)
return (-1);
return (0);
}
int int
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx) cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
@ -69,8 +58,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->cmd_if = xstrdup(args->argv[1]); cdata->cmd_if = xstrdup(args->argv[1]);
if (args->argc == 4) if (args->argc == 3)
cdata->cmd_else = xstrdup(args->argv[3]); cdata->cmd_else = xstrdup(args->argv[2]);
else else
cdata->cmd_else = NULL; cdata->cmd_else = NULL;
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx); memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
@ -91,8 +80,7 @@ cmd_if_shell_callback(struct job *job)
struct cmd_if_shell_data *cdata = job->data; struct cmd_if_shell_data *cdata = job->data;
struct cmd_ctx *ctx = &cdata->ctx; struct cmd_ctx *ctx = &cdata->ctx;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
char *cmd; char *cause, *cmd;
char *cause;
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) { if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) {
cmd = cdata->cmd_else; cmd = cdata->cmd_else;

10
tmux.1
View File

@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\" .\"
.Dd $Mdocdate: October 23 2011 $ .Dd $Mdocdate: October 27 2011 $
.Dt TMUX 1 .Dt TMUX 1
.Os .Os
.Sh NAME .Sh NAME
@ -2975,13 +2975,15 @@ Miscellaneous commands are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Ic clock-mode Op Fl t Ar target-pane .It Ic clock-mode Op Fl t Ar target-pane
Display a large clock. Display a large clock.
.It Ic if-shell Ar shell-command command .It Ic if-shell Ar shell-command command Op Ar command
.D1 (alias: Ic if ) .D1 (alias: Ic if )
Execute Execute the first
.Ar command .Ar command
if if
.Ar shell-command .Ar shell-command
returns success. returns success or the second
.Ar command
otherwise.
.It Ic lock-server .It Ic lock-server
.D1 (alias: Ic lock ) .D1 (alias: Ic lock )
Lock each client individually by running the command specified by the Lock each client individually by running the command specified by the