mirror of
https://github.com/tmux/tmux.git
synced 2024-12-04 19:58:48 +00:00
Merge branch 'obsd-master'
This commit is contained in:
commit
3ea36830f3
@ -54,8 +54,7 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
struct client *c = item->client, *c_loop;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
char *cause, *cwd;
|
||||
struct format_tree *ft;
|
||||
char *cause;
|
||||
|
||||
if (RB_EMPTY(&sessions)) {
|
||||
cmdq_error(item, "no sessions");
|
||||
@ -77,13 +76,8 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
}
|
||||
|
||||
if (cflag != NULL) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
cwd = format_expand(ft, cflag);
|
||||
format_free(ft);
|
||||
|
||||
free((void *)s->cwd);
|
||||
s->cwd = cwd;
|
||||
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
||||
}
|
||||
|
||||
if (c->session != NULL) {
|
||||
|
@ -48,6 +48,7 @@ static enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.sflag.wl;
|
||||
struct session *src_s = item->state.sflag.s;
|
||||
struct session *dst_s = item->state.tflag.s;
|
||||
@ -55,7 +56,6 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window *w = wl->window;
|
||||
char *name, *cause;
|
||||
int idx = item->state.tflag.idx;
|
||||
struct format_tree *ft;
|
||||
const char *template;
|
||||
char *cp;
|
||||
|
||||
@ -106,15 +106,9 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = BREAK_PANE_TEMPLATE;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, dst_s, wl, wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cp = format_single(item, template, c, dst_s, wl, wp);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
@ -69,10 +69,10 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
char *shellcmd, *cmd, *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct format_tree *ft;
|
||||
const char *cwd;
|
||||
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
@ -82,11 +82,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
cwd = NULL;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, wl, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (args_has(args, 'F')) {
|
||||
cmd = NULL;
|
||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
||||
|
@ -78,7 +78,6 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
char **argv, *cause, *cp;
|
||||
int detached, already_attached, idx, argc;
|
||||
u_int sx, sy;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
@ -155,10 +154,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
to_free = cwd = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, NULL, NULL, NULL);
|
||||
} else if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||
cwd = c->cwd;
|
||||
else
|
||||
@ -322,15 +319,9 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_SESSION_TEMPLATE;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, NULL, NULL);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cp = format_single(item, template, c, s, NULL, NULL);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
if (!detached)
|
||||
|
@ -59,7 +59,6 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
const char *cmd, *path, *template, *cwd, *to_free;
|
||||
char **argv, *cause, *cp;
|
||||
int argc, detached;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
@ -95,10 +94,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, NULL, NULL);
|
||||
cwd = to_free = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
||||
} else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else
|
||||
@ -142,15 +139,9 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, NULL);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cp = format_single(item, template, c, s, wl, NULL);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
if (to_free != NULL)
|
||||
|
@ -86,11 +86,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_run_shell_data *cdata;
|
||||
char *shellcmd;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct format_tree *ft;
|
||||
const char *cwd;
|
||||
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
@ -100,13 +99,8 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
cwd = NULL;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, wl, wp);
|
||||
shellcmd = format_expand(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->cmd = shellcmd;
|
||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
|
||||
if (args_has(args, 't') && wp != NULL)
|
||||
cdata->wp_id = wp->id;
|
||||
@ -116,7 +110,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!args_has(args, 'b'))
|
||||
cdata->item = item;
|
||||
|
||||
job_run(shellcmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
|
||||
job_run(cdata->cmd, s, cwd, cmd_run_shell_callback, cmd_run_shell_free,
|
||||
cdata);
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
|
@ -53,6 +53,7 @@ static enum cmd_retval
|
||||
cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w = wl->window;
|
||||
@ -64,7 +65,6 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int argc, size, percentage;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
struct format_tree *ft;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
@ -91,10 +91,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, NULL, NULL);
|
||||
to_free = cwd = format_expand(ft, args_get(args, 'c'));
|
||||
format_free(ft);
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
||||
} else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else
|
||||
@ -167,15 +165,9 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = SPLIT_WINDOW_TEMPLATE;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, item->state.c, s, wl, new_wp);
|
||||
|
||||
cp = format_expand(ft, template);
|
||||
cp = format_single(item, template, c, s, wl, new_wp);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
|
||||
format_free(ft);
|
||||
}
|
||||
notify_window("window-layout-changed", w);
|
||||
|
||||
|
@ -64,10 +64,9 @@ control_notify_window_layout_changed(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct format_tree *ft;
|
||||
struct winlink *wl;
|
||||
const char *template;
|
||||
char *expanded;
|
||||
char *cp;
|
||||
|
||||
template = "%layout-change #{window_id} #{window_layout} "
|
||||
"#{window_visible_layout} #{window_flags}";
|
||||
@ -88,15 +87,12 @@ control_notify_window_layout_changed(struct window *w)
|
||||
if (w->layout_root == NULL)
|
||||
continue;
|
||||
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
if (wl != NULL) {
|
||||
format_defaults(ft, c, NULL, wl, NULL);
|
||||
expanded = format_expand(ft, template);
|
||||
control_write(c, "%s", expanded);
|
||||
free(expanded);
|
||||
cp = format_single(NULL, template, c, NULL, wl, NULL);
|
||||
control_write(c, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
format_free(ft);
|
||||
}
|
||||
}
|
||||
|
||||
|
17
format.c
17
format.c
@ -519,7 +519,6 @@ format_merge(struct format_tree *ft, struct format_tree *from)
|
||||
if (fe->value != NULL)
|
||||
format_add(ft, fe->key, "%s", fe->value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Create a new tree. */
|
||||
@ -1081,6 +1080,22 @@ format_expand(struct format_tree *ft, const char *fmt)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Expand a single string. */
|
||||
char *
|
||||
format_single(struct cmdq_item *item, const char *fmt, struct client *c,
|
||||
struct session *s, struct winlink *wl, struct window_pane *wp)
|
||||
{
|
||||
struct format_tree *ft;
|
||||
char *expanded;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
|
||||
expanded = format_expand(ft, fmt);
|
||||
format_free(ft);
|
||||
return (expanded);
|
||||
}
|
||||
|
||||
/* Set defaults for any of arguments that are not NULL. */
|
||||
void
|
||||
format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
||||
|
3
tmux.h
3
tmux.h
@ -1510,6 +1510,9 @@ void printflike(3, 4) format_add(struct format_tree *, const char *,
|
||||
const char *, ...);
|
||||
char *format_expand_time(struct format_tree *, const char *, time_t);
|
||||
char *format_expand(struct format_tree *, const char *);
|
||||
char *format_single(struct cmdq_item *, const char *,
|
||||
struct client *, struct session *, struct winlink *,
|
||||
struct window_pane *);
|
||||
void format_defaults(struct format_tree *, struct client *,
|
||||
struct session *, struct winlink *, struct window_pane *);
|
||||
void format_defaults_window(struct format_tree *, struct window *);
|
||||
|
@ -1604,29 +1604,23 @@ window_copy_copy_buffer(struct window_pane *wp, const char *bufname, void *buf,
|
||||
}
|
||||
|
||||
static void
|
||||
window_copy_copy_pipe(struct window_pane *wp, struct session *sess,
|
||||
window_copy_copy_pipe(struct window_pane *wp, struct session *s,
|
||||
const char *bufname, const char *arg)
|
||||
{
|
||||
void *buf;
|
||||
size_t len;
|
||||
struct job *job;
|
||||
struct format_tree *ft;
|
||||
char *expanded;
|
||||
void *buf;
|
||||
size_t len;
|
||||
struct job *job;
|
||||
char *expanded;
|
||||
|
||||
buf = window_copy_get_selection(wp, &len);
|
||||
if (buf == NULL)
|
||||
return;
|
||||
expanded = format_single(NULL, arg, NULL, s, NULL, wp);
|
||||
|
||||
ft = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, sess, NULL, wp);
|
||||
expanded = format_expand(ft, arg);
|
||||
|
||||
job = job_run(expanded, sess, NULL, NULL, NULL, NULL);
|
||||
job = job_run(expanded, s, NULL, NULL, NULL, NULL);
|
||||
bufferevent_write(job->event, buf, len);
|
||||
|
||||
free(expanded);
|
||||
format_free(ft);
|
||||
|
||||
window_copy_copy_buffer(wp, bufname, buf, len);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user