diff options
Diffstat (limited to 'cmd-pipe-pane.c')
-rw-r--r-- | cmd-pipe-pane.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index 611ad8cf..49b156c6 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -1,4 +1,4 @@ -/* $Id$ */ +/* $OpenBSD$ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -21,6 +21,7 @@ #include <errno.h> #include <fcntl.h> +#include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> @@ -40,7 +41,6 @@ const struct cmd_entry cmd_pipe_pane_entry = { "ot:", 0, 1, "[-o] " CMD_TARGET_PANE_USAGE " [command]", 0, - NULL, cmd_pipe_pane_exec }; @@ -49,11 +49,14 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) { struct args *args = self->args; struct client *c; + struct session *s; + struct winlink *wl; struct window_pane *wp; - char *command; + char *cmd; int old_fd, pipe_fd[2], null_fd; + struct format_tree *ft; - if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL) + if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL) return (CMD_RETURN_ERROR); c = cmd_find_client(cmdq, NULL, 1); @@ -84,10 +87,18 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) return (CMD_RETURN_ERROR); } + /* Expand the command. */ + ft = format_create(); + format_defaults(ft, c, s, wl, wp); + cmd = format_expand_time(ft, args->argv[0], time(NULL)); + format_free(ft); + /* Fork the child. */ switch (fork()) { case -1: cmdq_error(cmdq, "fork error: %s", strerror(errno)); + + free(cmd); return (CMD_RETURN_ERROR); case 0: /* Child process. */ @@ -109,9 +120,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) closefrom(STDERR_FILENO + 1); - command = status_replace( - c, NULL, NULL, NULL, args->argv[0], time(NULL), 0); - execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL); + execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL); _exit(1); default: /* Parent process. */ @@ -125,6 +134,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) bufferevent_enable(wp->pipe_event, EV_WRITE); setblocking(wp->pipe_fd, 0); + + free(cmd); return (CMD_RETURN_NORMAL); } } |