summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-01-01 01:33:08 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-01-01 01:33:08 +0000
commit83fc2089c69ef18c917b4646d20a5a0100ba72a1 (patch)
treeb3a250254a5a9cd2c04e563a92731e7365514c69 /usr.bin
parent3acf300bbec4893d8bd3e914fabe1e4849df2862 (diff)
Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-new-window.c15
-rw-r--r--usr.bin/tmux/cmd-split-window.c20
-rw-r--r--usr.bin/tmux/tmux.112
3 files changed, 36 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index bf17196cbda..07612bfa141 100644
--- a/usr.bin/tmux/cmd-new-window.c
+++ b/usr.bin/tmux/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-window.c,v 1.15 2010/06/27 02:56:59 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.16 2011/01/01 01:33:07 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,11 +39,12 @@ struct cmd_new_window_data {
int flag_insert_after;
int flag_detached;
int flag_kill;
+ int flag_print;
};
const struct cmd_entry cmd_new_window_entry = {
"new-window", "neww",
- "[-adk] [-n window-name] [-t target-window] [command]",
+ "[-adkP] [-n window-name] [-t target-window] [command]",
0, "",
cmd_new_window_init,
cmd_new_window_parse,
@@ -65,6 +66,7 @@ cmd_new_window_init(struct cmd *self, unused int arg)
data->flag_insert_after = 0;
data->flag_detached = 0;
data->flag_kill = 0;
+ data->flag_print = 0;
}
int
@@ -76,7 +78,7 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
self->entry->init(self, KEYC_NONE);
data = self->data;
- while ((opt = getopt(argc, argv, "adkt:n:")) != -1) {
+ while ((opt = getopt(argc, argv, "adkt:n:P")) != -1) {
switch (opt) {
case 'a':
data->flag_insert_after = 1;
@@ -95,6 +97,9 @@ cmd_new_window_parse(struct cmd *self, int argc, char **argv, char **cause)
if (data->name == NULL)
data->name = xstrdup(optarg);
break;
+ case 'P':
+ data->flag_print = 1;
+ break;
default:
goto usage;
}
@@ -198,6 +203,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
} else
server_status_session_group(s);
+ if (data->flag_print)
+ ctx->print(ctx, "%s:%u", s->name, wl->idx);
return (0);
}
@@ -226,6 +233,8 @@ cmd_new_window_print(struct cmd *self, char *buf, size_t len)
return (off);
if (off < len && data->flag_detached)
off += xsnprintf(buf + off, len - off, " -d");
+ if (off < len && data->flag_print)
+ off += xsnprintf(buf + off, len - off, " -P");
if (off < len && data->target != NULL)
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
if (off < len && data->name != NULL)
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index b680454cef1..719760769a3 100644
--- a/usr.bin/tmux/cmd-split-window.c
+++ b/usr.bin/tmux/cmd-split-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-split-window.c,v 1.20 2010/06/27 02:56:59 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.21 2011/01/01 01:33:07 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,13 +39,14 @@ struct cmd_split_window_data {
char *cmd;
int flag_detached;
int flag_horizontal;
+ int flag_print;
int percentage;
int size;
};
const struct cmd_entry cmd_split_window_entry = {
"split-window", "splitw",
- "[-dhv] [-p percentage|-l size] [-t target-pane] [command]",
+ "[-dhvP] [-p percentage|-l size] [-t target-pane] [command]",
0, "",
cmd_split_window_init,
cmd_split_window_parse,
@@ -64,6 +65,7 @@ cmd_split_window_init(struct cmd *self, int key)
data->cmd = NULL;
data->flag_detached = 0;
data->flag_horizontal = 0;
+ data->flag_print = 0;
data->percentage = -1;
data->size = -1;
@@ -87,7 +89,7 @@ cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
self->entry->init(self, KEYC_NONE);
data = self->data;
- while ((opt = getopt(argc, argv, "dhl:p:t:v")) != -1) {
+ while ((opt = getopt(argc, argv, "dhl:p:Pt:v")) != -1) {
switch (opt) {
case 'd':
data->flag_detached = 1;
@@ -117,6 +119,9 @@ cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
goto error;
}
break;
+ case 'P':
+ data->flag_print = 1;
+ break;
case 'v':
data->flag_horizontal = 0;
break;
@@ -153,7 +158,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct environ env;
char *cmd, *cwd, *cause;
const char *shell;
- u_int hlimit;
+ u_int hlimit, paneidx;
int size;
enum layout_type type;
struct layout_cell *lc;
@@ -217,6 +222,11 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
server_status_session(s);
environ_free(&env);
+
+ if (data->flag_print) {
+ paneidx = window_pane_index(wl->window, new_wp);
+ ctx->print(ctx, "%s:%u.%u", s->name, wl->idx, paneidx);
+ }
return (0);
error:
@@ -253,6 +263,8 @@ cmd_split_window_print(struct cmd *self, char *buf, size_t len)
off += xsnprintf(buf + off, len - off, " -d");
if (off < len && data->flag_horizontal)
off += xsnprintf(buf + off, len - off, " -h");
+ if (off < len && data->flag_print)
+ off += xsnprintf(buf + off, len - off, " -P");
if (off < len && data->size > 0)
off += xsnprintf(buf + off, len - off, " -l %d", data->size);
if (off < len && data->percentage > 0) {
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index dba09a27c4e..159042bd44a 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.200 2010/12/31 00:41:11 jmc Exp $
+.\" $OpenBSD: tmux.1,v 1.201 2011/01/01 01:33:07 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 31 2010 $
+.Dd $Mdocdate: January 1 2011 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1097,7 +1097,7 @@ except the window at
is moved to
.Ar dst-window .
.It Xo Ic new-window
-.Op Fl adk
+.Op Fl adkP
.Op Fl n Ar window-name
.Op Fl t Ar target-window
.Op Ar shell-command
@@ -1145,6 +1145,10 @@ New windows will automatically have
.Dq TERM=screen
added to their environment, but care must be taken not to reset this in shell
start-up files.
+.Pp
+The
+.Fl P
+option prints the location 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.
@@ -1281,7 +1285,7 @@ target pane is used.
Select the window at
.Ar target-window .
.It Xo Ic split-window
-.Op Fl dhv
+.Op Fl dhvP
.Oo Fl l
.Ar size |
.Fl p Ar percentage Oc