Expand format variables in the run-shell and if-shell shell commands,

from Thiago Padilha.
This commit is contained in:
Nicholas Marriott 2013-03-24 09:33:35 +00:00
parent 86adcd4b26
commit 66edb3392b
3 changed files with 55 additions and 7 deletions

View File

@ -36,8 +36,8 @@ 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, 3, "t:", 2, 3,
"shell-command command [command]", CMD_TARGET_PANE_USAGE " shell-command command [command]",
0, 0,
NULL, NULL,
NULL, NULL,
@ -55,7 +55,22 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct args *args = self->args; struct args *args = self->args;
struct cmd_if_shell_data *cdata; struct cmd_if_shell_data *cdata;
const char *shellcmd = args->argv[0]; char *shellcmd;
struct session *s;
struct winlink *wl;
struct window_pane *wp;
struct format_tree *ft;
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
if (wl == NULL)
return (CMD_RETURN_ERROR);
ft = format_create();
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->cmd_if = xstrdup(args->argv[1]); cdata->cmd_if = xstrdup(args->argv[1]);
@ -68,6 +83,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_ref_ctx(ctx); cmd_ref_ctx(ctx);
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata); job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
free(shellcmd);
return (CMD_RETURN_YIELD); /* don't let client exit */ return (CMD_RETURN_YIELD); /* don't let client exit */
} }

View File

@ -75,14 +75,25 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{ {
struct args *args = self->args; struct args *args = self->args;
struct cmd_run_shell_data *cdata; struct cmd_run_shell_data *cdata;
const char *shellcmd = args->argv[0]; char *shellcmd;
struct session *s;
struct winlink *wl;
struct window_pane *wp; struct window_pane *wp;
struct format_tree *ft;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL) wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
if (wl == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
ft = format_create();
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
cdata = xmalloc(sizeof *cdata); cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]); cdata->cmd = shellcmd;
cdata->wp_id = wp->id; cdata->wp_id = wp->id;
cdata->ctx = ctx; cdata->ctx = ctx;

23
tmux.1
View File

@ -2704,6 +2704,13 @@ Set clock colour.
.Xc .Xc
Set clock hour format. Set clock hour format.
.Pp .Pp
.It Ic command-prefix Ar string
String prefixed to commands (apart from a plain shell as set by the
.Ic default-shell
option).
The default is
.Ql "exec\ " .
.Pp
.It Ic force-height Ar height .It Ic force-height Ar height
.It Ic force-width Ar width .It Ic force-width Ar width
Prevent Prevent
@ -3016,6 +3023,7 @@ The following variables are available, where appropriate:
.It Li "mouse_standard_flag" Ta "Pane mouse standard flag" .It Li "mouse_standard_flag" Ta "Pane mouse standard flag"
.It Li "mouse_utf8_flag" Ta "Pane mouse UTF-8 flag" .It Li "mouse_utf8_flag" Ta "Pane mouse UTF-8 flag"
.It Li "pane_active" Ta "1 if active pane" .It Li "pane_active" Ta "1 if active pane"
.It Li "pane_current_command" Ta "Current command if available"
.It Li "pane_current_path" Ta "Current path if available" .It Li "pane_current_path" Ta "Current path if available"
.It Li "pane_dead" Ta "1 if pane is dead" .It Li "pane_dead" Ta "1 if pane is dead"
.It Li "pane_height" Ta "Height of pane" .It Li "pane_height" Ta "Height of pane"
@ -3025,6 +3033,7 @@ The following variables are available, where appropriate:
.It Li "pane_pid" Ta "PID of first process in pane" .It Li "pane_pid" Ta "PID of first process in pane"
.It Li "pane_start_command" Ta "Command pane started with" .It Li "pane_start_command" Ta "Command pane started with"
.It Li "pane_start_path" Ta "Path pane started with" .It Li "pane_start_path" Ta "Path pane started with"
.It Li "pane_tabs" Ta "Pane tab positions"
.It Li "pane_title" Ta "Title of pane" .It Li "pane_title" Ta "Title of pane"
.It Li "pane_tty" Ta "Pseudo terminal of pane" .It Li "pane_tty" Ta "Pseudo terminal of pane"
.It Li "pane_width" Ta "Width of pane" .It Li "pane_width" Ta "Width of pane"
@ -3455,7 +3464,11 @@ 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 Op Ar command .It Xo Ic if-shell
.Op Fl t Ar target-pane
.Ar shell-command command
.Op Ar command
.Xc
.D1 (alias: Ic if ) .D1 (alias: Ic if )
Execute the first Execute the first
.Ar command .Ar command
@ -3464,6 +3477,10 @@ if
returns success or the second returns success or the second
.Ar command .Ar command
otherwise. otherwise.
Before being executed, shell-command is expanded using the rules specified in the
.Sx FORMATS
section, including those relevant to
.Ar target-pane .
.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
@ -3477,6 +3494,10 @@ option.
Execute Execute
.Ar shell-command .Ar shell-command
in the background without creating a window. in the background without creating a window.
Before being executed, shell-command is expanded using the rules specified in
the
.Sx FORMATS
section.
After it finishes, any output to stdout is displayed in copy mode (in the pane After it finishes, any output to stdout is displayed in copy mode (in the pane
specified by specified by
.Fl t .Fl t