Thinking about this I wonder if it is better to do this and add a target-pane to display-message and #D for pane id, then you can do eg:
tmux display -p -P `tmux neww -P` '#D' Not sure I like -P though, think I would prefer to change -t to -c and use -t but I don't know if people use it already. Perhaps it is unlikely. This makes status_replace even more messy though... Index: cmd-display-message.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/cmd-display-message.c,v retrieving revision 1.8 diff -u -p -r1.8 cmd-display-message.c --- cmd-display-message.c 4 Jan 2011 00:42:46 -0000 1.8 +++ cmd-display-message.c 28 Mar 2011 23:37:46 -0000 @@ -30,8 +30,8 @@ int cmd_display_message_exec(struct cmd const struct cmd_entry cmd_display_message_entry = { "display-message", "display", - "pt:", 0, 1, - "[-p] " CMD_TARGET_CLIENT_USAGE " [message]", + "pP:t:", 0, 1, + "[-p] [-P target-pane] " CMD_TARGET_CLIENT_USAGE " [message]", 0, NULL, NULL, @@ -43,18 +43,31 @@ cmd_display_message_exec(struct cmd *sel { struct args *args = self->args; struct client *c; + struct session *s; + struct winlink *wl; + struct window_pane *wp; const char *template; char *msg; if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL) return (-1); + if (args_has(args, 'P') != NULL) { + wl = cmd_find_pane(ctx, args_get(args, 'P'), &s, &wp); + if (wl == NULL) + return (-1); + } else { + s = NULL; + wl = NULL; + wp = NULL; + } + if (args->argc == 0) template = "[#S] #I:#W, current pane #P - (%H:%M %d-%b-%y)"; else template = args->argv[0]; - msg = status_replace(c, NULL, template, time(NULL), 0); + msg = status_replace(c, s, wl, wp, template, time(NULL), 0); if (args_has(self->args, 'p')) ctx->print(ctx, "%s", msg); else Index: cmd-pipe-pane.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/cmd-pipe-pane.c,v retrieving revision 1.18 diff -u -p -r1.18 cmd-pipe-pane.c --- cmd-pipe-pane.c 8 Jan 2011 01:52:36 -0000 1.18 +++ cmd-pipe-pane.c 28 Mar 2011 23:37:46 -0000 @@ -113,7 +113,8 @@ cmd_pipe_pane_exec(struct cmd *self, str closefrom(STDERR_FILENO + 1); - command = status_replace(c, NULL, args->argv[0], time(NULL), 0); + command = status_replace( + c, NULL, NULL, NULL, args->argv[0], time(NULL), 0); execl(_PATH_BSHELL, "sh", "-c", command, (char *) NULL); _exit(1); default: Index: server-client.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/server-client.c,v retrieving revision 1.51 diff -u -p -r1.51 server-client.c --- server-client.c 26 Jan 2011 01:54:56 -0000 1.51 +++ server-client.c 28 Mar 2011 23:37:46 -0000 @@ -614,7 +614,7 @@ server_client_set_title(struct client *c template = options_get_string(&s->options, "set-titles-string"); - title = status_replace(c, NULL, template, time(NULL), 1); + title = status_replace(c, NULL, NULL, NULL, template, time(NULL), 1); if (c->title == NULL || strcmp(title, c->title) != 0) { if (c->title != NULL) xfree(c->title); Index: status.c =================================================================== RCS file: /cvs/src/usr.bin/tmux/status.c,v retrieving revision 1.71 diff -u -p -r1.71 status.c --- status.c 26 Jan 2011 01:54:56 -0000 1.71 +++ status.c 28 Mar 2011 23:37:47 -0000 @@ -38,8 +38,8 @@ void status_job_free(void *); void status_job_callback(struct job *); char *status_print( struct client *, struct winlink *, time_t, struct grid_cell *); -void status_replace1(struct client *, - struct winlink *, char **, char **, char *, size_t, int); +void status_replace1(struct client *, struct session *, struct winlink *, + struct window_pane *, char **, char **, char *, size_t, int); void status_message_callback(int, short, void *); const char *status_prompt_up_history(u_int *); @@ -80,8 +80,8 @@ status_redraw_get_left(struct client *c, if (attr != 0) gc->attr = attr; - left = status_replace( - c, NULL, options_get_string(&s->options, "status-left"), t, 1); + left = status_replace(c, NULL, + NULL, NULL, options_get_string(&s->options, "status-left"), t, 1); *size = options_get_number(&s->options, "status-left-length"); leftlen = screen_write_cstrlen(utf8flag, "%s", left); @@ -110,8 +110,8 @@ status_redraw_get_right(struct client *c if (attr != 0) gc->attr = attr; - right = status_replace( - c, NULL, options_get_string(&s->options, "status-right"), t, 1); + right = status_replace(c, NULL, + NULL, NULL, options_get_string(&s->options, "status-right"), t, 1); *size = options_get_number(&s->options, "status-right-length"); rightlen = screen_write_cstrlen(utf8flag, "%s", right); @@ -347,16 +347,20 @@ out: /* Replace a single special sequence (prefixed by #). */ void -status_replace1(struct client *c,struct winlink *wl, - char **iptr, char **optr, char *out, size_t outsize, int jobsflag) -{ - struct session *s = c->session; - char ch, tmp[256], *ptr, *endptr, *freeptr; - size_t ptrlen; - long limit; +status_replace1(struct client *c, struct session *s, struct winlink *wl, + struct window_pane *wp, char **iptr, char **optr, char *out, + size_t outsize, int jobsflag) +{ + char ch, tmp[256], *ptr, *endptr, *freeptr; + size_t ptrlen; + long limit; + if (s == NULL) + s = c->session; if (wl == NULL) wl = s->curw; + if (wp == NULL) + wp = wl->window->active; errno = 0; limit = strtol(*iptr, &endptr, 10); @@ -379,6 +383,10 @@ status_replace1(struct client *c,struct if ((ptr = status_find_job(c, iptr)) == NULL) return; goto do_replace; + case 'D': + xsnprintf(tmp, sizeof tmp, "%%%u", wp->id); + ptr = tmp; + goto do_replace; case 'H': if (gethostname(tmp, sizeof tmp) != 0) fatal("gethostname failed"); @@ -389,15 +397,15 @@ status_replace1(struct client *c,struct ptr = tmp; goto do_replace; case 'P': - xsnprintf(tmp, sizeof tmp, "%u", - window_pane_index(wl->window, wl->window->active)); + xsnprintf( + tmp, sizeof tmp, "%u", window_pane_index(wl->window, wp)); ptr = tmp; goto do_replace; case 'S': ptr = s->name; goto do_replace; case 'T': - ptr = wl->window->active->base.title; + ptr = wp->base.title; goto do_replace; case 'W': ptr = wl->window->name; @@ -449,8 +457,8 @@ skip_to: /* Replace special sequences in fmt. */ char * -status_replace(struct client *c, - struct winlink *wl, const char *fmt, time_t t, int jobsflag) +status_replace(struct client *c, struct session *s, struct winlink *wl, + struct window_pane *wp, const char *fmt, time_t t, int jobsflag) { static char out[BUFSIZ]; char in[BUFSIZ], ch, *iptr, *optr; @@ -470,7 +478,8 @@ status_replace(struct client *c, *optr++ = ch; continue; } - status_replace1(c, wl, &iptr, &optr, out, sizeof out, jobsflag); + status_replace1( + c, s, wl, wp, &iptr, &optr, out, sizeof out, jobsflag); } *optr = '\0'; @@ -657,7 +666,7 @@ status_print( gc->attr = attr; } - text = status_replace(c, wl, fmt, t, 1); + text = status_replace(c, NULL, wl, NULL, fmt, t, 1); return (text); } Index: tmux.1 =================================================================== RCS file: /cvs/src/usr.bin/tmux/tmux.1,v retrieving revision 1.214 diff -u -p -r1.214 tmux.1 --- tmux.1 28 Mar 2011 23:13:00 -0000 1.214 +++ tmux.1 28 Mar 2011 23:37:48 -0000 @@ -2611,6 +2611,7 @@ This command works only from inside .Nm . .It Xo Ic display-message .Op Fl p +.Op Fl P Ar target-pane .Op Fl t Ar target-client .Op Ar message .Xc @@ -2625,7 +2626,12 @@ The format of .Ar message is as for .Ic status-left , -with the exception that #() are not handled. +with the exception that #() are not handled; information is taken from +.Ar target-pane +if +.Fl P +is given, otherwise the active pane for the session attached to +.Ar target-client . .El .Sh BUFFERS .Nm Index: tmux.h =================================================================== RCS file: /cvs/src/usr.bin/tmux/tmux.h,v retrieving revision 1.276 diff -u -p -r1.276 tmux.h --- tmux.h 28 Mar 2011 19:44:31 -0000 1.276 +++ tmux.h 28 Mar 2011 23:37:49 -0000 @@ -1666,8 +1666,8 @@ RB_PROTOTYPE(status_out_tree, status_out void status_free_jobs(struct status_out_tree *); void status_update_jobs(struct client *); int status_redraw(struct client *); -char *status_replace( - struct client *, struct winlink *, const char *, time_t, int); +char *status_replace(struct client *, struct session *, + struct winlink *, struct window_pane *, const char *, time_t, int); void printflike2 status_message_set(struct client *, const char *, ...); void status_message_clear(struct client *); int status_message_redraw(struct client *); On Sat, Mar 26, 2011 at 06:47:36PM -0400, Ben Boeckel wrote: > From 2136eb7e2e14af40397a4e33746133050bfd5dbf Mon Sep 17 00:00:00 2001 > From: Ben Boeckel <maths...@gmail.com> > Date: Sat, 26 Mar 2011 18:28:50 -0400 > Subject: [PATCH 8/8] Add -I flag to new-window and split-window > > This is similar to the -P flag, but instead prints the ID of the new > window. > --- > cmd-new-window.c | 6 ++++-- > cmd-split-window.c | 6 ++++-- > tmux.1 | 16 ++++++++++++++-- > 3 files changed, 22 insertions(+), 6 deletions(-) > > diff --git a/cmd-new-window.c b/cmd-new-window.c > index 79e301f..85b025d 100644 > --- a/cmd-new-window.c > +++ b/cmd-new-window.c > @@ -30,8 +30,8 @@ int cmd_new_window_exec(struct cmd *, struct cmd_ctx *); > > const struct cmd_entry cmd_new_window_entry = { > "new-window", "neww", > - "adkn:Pt:", 0, 1, > - "[-adk] [-n window-name] [-t target-window] [command]", > + "adkn:PIt:", 0, 1, > + "[-adkPI] [-n window-name] [-t target-window] [command]", > 0, > NULL, > NULL, > @@ -122,5 +122,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx) > > if (args_has(args, 'P')) > ctx->print(ctx, "%s:%u", s->name, wl->idx); > + if (args_has(args, 'I')) > + ctx->print(ctx, "%%%u", wl->window->active->id); > return (0); > } > diff --git a/cmd-split-window.c b/cmd-split-window.c > index 1aedf90..d19a7b3 100644 > --- a/cmd-split-window.c > +++ b/cmd-split-window.c > @@ -32,8 +32,8 @@ int cmd_split_window_exec(struct cmd *, struct cmd_ctx *); > > const struct cmd_entry cmd_split_window_entry = { > "split-window", "splitw", > - "dl:hp:Pt:v", 0, 1, > - "[-dhvP] [-p percentage|-l size] [-t target-pane] [command]", > + "dl:hp:PIt:v", 0, 1, > + "[-dhvPI] [-p percentage|-l size] [-t target-pane] [command]", > 0, > cmd_split_window_key_binding, > NULL, > @@ -140,6 +140,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx > *ctx) > paneidx = window_pane_index(wl->window, new_wp); > ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx); > } > + if (args_has(args, 'I')) > + ctx->print(ctx, "%%%u", new_wp->id); > return (0); > > error: > diff --git a/tmux.1 b/tmux.1 > index 232d292..c229686 100644 > --- a/tmux.1 > +++ b/tmux.1 > @@ -1131,7 +1131,7 @@ except the window at > is moved to > .Ar dst-window . > .It Xo Ic new-window > -.Op Fl adkP > +.Op Fl adkPI > .Op Fl n Ar window-name > .Op Fl t Ar target-window > .Op Ar shell-command > @@ -1183,6 +1183,10 @@ start-up files. > The > .Fl P > option prints the location of the new window after it has been created. > +.Pp > +The > +.Fl I > +option prints the id of the new window after it has been created. > .It Ic next-layout Op Fl t Ar target-window > .D1 (alias: Ic nextl ) > Move a window to the next layout and rearrange the panes to fit. > @@ -1345,7 +1349,7 @@ and > .Ic previous-window > commands. > .It Xo Ic split-window > -.Op Fl dhvP > +.Op Fl dhvPI > .Oo Fl l > .Ar size | > .Fl p Ar percentage Oc > @@ -1370,6 +1374,14 @@ cells (for horizontal split), or as a percentage, > respectively. > All other options have the same meaning as for the > .Ic new-window > command. > +.Pp > +The > +.Fl P > +option prints the location of the new window after it has been created. > +.Pp > +The > +.Fl I > +option prints the id of the new window after it has been created. > .It Xo Ic swap-pane > .Op Fl dDU > .Op Fl s Ar src-pane > -- > 1.7.4.1 > ------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf _______________________________________________ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users