diff options
author | nicm <nicm> | 2015-02-06 17:11:39 +0000 |
---|---|---|
committer | nicm <nicm> | 2015-02-06 17:11:39 +0000 |
commit | 03758a50dc21b7c77b75f689d06f81292266c20a (patch) | |
tree | cae22c5417ac2176a5e082e71705a10d0f18a992 /cmd-pipe-pane.c | |
parent | 83a8e1fd20e3cbd6da38d0b4d6973cad0484c27b (diff) | |
download | rtmux-03758a50dc21b7c77b75f689d06f81292266c20a.tar.gz rtmux-03758a50dc21b7c77b75f689d06f81292266c20a.tar.bz2 rtmux-03758a50dc21b7c77b75f689d06f81292266c20a.zip |
Add format_expand_time and use it instead of status_replace where
command execution is not needed.
Diffstat (limited to 'cmd-pipe-pane.c')
-rw-r--r-- | cmd-pipe-pane.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/cmd-pipe-pane.c b/cmd-pipe-pane.c index fde6baaa..df706432 100644 --- a/cmd-pipe-pane.c +++ b/cmd-pipe-pane.c @@ -22,6 +22,7 @@ #include <errno.h> #include <fcntl.h> #include <paths.h> +#include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> @@ -49,11 +50,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 +88,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,8 +121,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq) closefrom(STDERR_FILENO + 1); - command = status_replace(c, 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. */ @@ -124,6 +135,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); } } |