summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2018-03-01 12:53:09 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2018-03-01 12:53:09 +0000
commitf0ee19bfeeceb04f95550ce4b57312e49abd17b8 (patch)
tree468b1b5b41d30467fc1b8461152677b9e29bd571 /usr.bin
parentfb7d3c10f87aa085e11fa984e274a1f7c1a3fb91 (diff)
Expand formats in window and session names.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-new-session.c49
-rw-r--r--usr.bin/tmux/cmd-new-window.c31
-rw-r--r--usr.bin/tmux/cmd-rename-session.c21
-rw-r--r--usr.bin/tmux/cmd-rename-window.c9
-rw-r--r--usr.bin/tmux/cmd-split-window.c22
5 files changed, 76 insertions, 56 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index 91cfbe5ca3c..aaadb90b1ce 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.109 2017/08/30 10:33:57 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.110 2018/03/01 12:53:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -73,14 +73,15 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct environ *env;
struct termios tio, *tiop;
struct session_group *sg;
- const char *newname, *errstr, *template, *group, *prefix;
- const char *path, *cmd, *cwd;
- char **argv, *cause, *cp, *to_free = NULL;
+ const char *errstr, *template, *group, *prefix;
+ const char *path, *cmd, *tmp;
+ char **argv, *cause, *cp, *newname, *cwd = NULL;
int detached, already_attached, idx, argc;
int is_control = 0;
u_int sx, sy;
struct environ_entry *envent;
struct cmd_find_state fs;
+ enum cmd_retval retval;
if (self->entry == &cmd_has_session_entry) {
/*
@@ -95,20 +96,24 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
- newname = args_get(args, 's');
- if (newname != NULL) {
+ newname = NULL;
+ if (args_has(args, 's')) {
+ newname = format_single(item, args_get(args, 's'), c, NULL,
+ NULL, NULL);
if (!session_check_name(newname)) {
cmdq_error(item, "bad session name: %s", newname);
- return (CMD_RETURN_ERROR);
+ goto error;
}
if ((as = session_find(newname)) != NULL) {
if (args_has(args, 'A')) {
- return (cmd_attach_session(item,
+ retval = cmd_attach_session(item,
newname, args_has(args, 'D'),
- 0, NULL, args_has(args, 'E')));
+ 0, NULL, args_has(args, 'E'));
+ free(newname);
+ return (retval);
}
cmdq_error(item, "duplicate session: %s", newname);
- return (CMD_RETURN_ERROR);
+ goto error;
}
}
@@ -149,14 +154,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
already_attached = 1;
/* Get the new session working directory. */
- if (args_has(args, 'c')) {
- cwd = args_get(args, 'c');
- to_free = format_single(item, cwd, c, NULL, NULL, NULL);
- cwd = to_free;
- } else if (c != NULL && c->session == NULL && c->cwd != NULL)
- cwd = c->cwd;
+ if ((tmp = args_get(args, 'c')) != NULL)
+ cwd = format_single(item, tmp, c, NULL, NULL, NULL);
+ else if (c != NULL && c->session == NULL && c->cwd != NULL)
+ cwd = xstrdup(c->cwd);
else
- cwd = ".";
+ cwd = xstrdup(".");
/*
* If this is a new client, check for nesting and save the termios
@@ -261,10 +264,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
}
/* Set the initial window name if one given. */
- if (argc >= 0 && args_has(args, 'n')) {
+ if (argc >= 0 && (tmp = args_get(args, 'n')) != NULL) {
+ cp = format_single(item, tmp, c, s, NULL, NULL);
w = s->curw->window;
- window_set_name(w, args_get(args, 'n'));
+ window_set_name(w, cp);
options_set_number(w->options, "automatic-rename", 0);
+ free(cp);
}
/*
@@ -331,10 +336,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
cmd_find_from_session(&fs, s, 0);
hooks_insert(s->hooks, item, &fs, "after-new-session");
- free(to_free);
+ free(cwd);
+ free(newname);
return (CMD_RETURN_NORMAL);
error:
- free(to_free);
+ free(cwd);
+ free(newname);
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c
index 863fb103ccd..a96d205cdb5 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.72 2017/08/30 10:33:57 nicm Exp $ */
+/* $OpenBSD: cmd-new-window.c,v 1.73 2018/03/01 12:53:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -57,8 +57,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
struct winlink *wl = item->target.wl;
struct client *c = cmd_find_client(item, NULL, 1);
int idx = item->target.idx;
- const char *cmd, *path, *template, *cwd;
- char **argv, *cause, *cp, *to_free = NULL;
+ const char *cmd, *path, *template, *tmp;
+ char **argv, *cause, *cp, *cwd, *name;
int argc, detached;
struct environ_entry *envent;
struct cmd_find_state fs;
@@ -93,14 +93,17 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if (envent != NULL)
path = envent->value;
- if (args_has(args, 'c')) {
- cwd = args_get(args, 'c');
- to_free = format_single(item, cwd, c, s, NULL, NULL);
- cwd = to_free;
- } else if (item->client != NULL && item->client->session == NULL)
- cwd = item->client->cwd;
+ if ((tmp = args_get(args, 'c')) != NULL)
+ cwd = format_single(item, tmp, c, s, NULL, NULL);
+ else if (item->client != NULL && item->client->session == NULL)
+ cwd = xstrdup(item->client->cwd);
else
- cwd = s->cwd;
+ cwd = xstrdup(s->cwd);
+
+ if ((tmp = args_get(args, 'n')) != NULL)
+ name = format_single(item, tmp, c, s, NULL, NULL);
+ else
+ name = NULL;
wl = NULL;
if (idx != -1)
@@ -124,7 +127,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if (idx == -1)
idx = -1 - options_get_number(s->options, "base-index");
- wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
+ wl = session_new(s, name, argc, argv, path, cwd, idx,
&cause);
if (wl == NULL) {
cmdq_error(item, "create window failed: %s", cause);
@@ -149,10 +152,12 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
cmd_find_from_winlink(&fs, wl, 0);
hooks_insert(s->hooks, item, &fs, "after-new-window");
- free(to_free);
+ free(name);
+ free(cwd);
return (CMD_RETURN_NORMAL);
error:
- free(to_free);
+ free(name);
+ free(cwd);
return (CMD_RETURN_ERROR);
}
diff --git a/usr.bin/tmux/cmd-rename-session.c b/usr.bin/tmux/cmd-rename-session.c
index b5c3876b24d..ca229719378 100644
--- a/usr.bin/tmux/cmd-rename-session.c
+++ b/usr.bin/tmux/cmd-rename-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-rename-session.c,v 1.26 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-rename-session.c,v 1.27 2018/03/01 12:53:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -46,26 +46,31 @@ const struct cmd_entry cmd_rename_session_entry = {
static enum cmd_retval
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
{
- struct args *args = self->args;
- struct session *s = item->target.s;
- const char *newname;
-
- newname = args->argv[0];
- if (strcmp(newname, s->name) == 0)
+ struct args *args = self->args;
+ struct client *c = cmd_find_client(item, NULL, 0);
+ struct session *s = item->target.s;
+ char *newname;
+
+ newname = format_single(item, args->argv[0], c, s, NULL, NULL);
+ if (strcmp(newname, s->name) == 0) {
+ free(newname);
return (CMD_RETURN_NORMAL);
+ }
if (!session_check_name(newname)) {
cmdq_error(item, "bad session name: %s", newname);
+ free(newname);
return (CMD_RETURN_ERROR);
}
if (session_find(newname) != NULL) {
cmdq_error(item, "duplicate session: %s", newname);
+ free(newname);
return (CMD_RETURN_ERROR);
}
RB_REMOVE(sessions, &sessions, s);
free(s->name);
- s->name = xstrdup(newname);
+ s->name = newname;
RB_INSERT(sessions, &sessions, s);
server_status_session(s);
diff --git a/usr.bin/tmux/cmd-rename-window.c b/usr.bin/tmux/cmd-rename-window.c
index 52950012755..bc8d4af22c8 100644
--- a/usr.bin/tmux/cmd-rename-window.c
+++ b/usr.bin/tmux/cmd-rename-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-rename-window.c,v 1.20 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-rename-window.c,v 1.21 2018/03/01 12:53:08 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -46,12 +46,17 @@ static enum cmd_retval
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = self->args;
+ struct client *c = cmd_find_client(item, NULL, 0);
+ struct session *s = item->target.s;
struct winlink *wl = item->target.wl;
+ char *newname;
- window_set_name(wl->window, args->argv[0]);
+ newname = format_single(item, args->argv[0], c, s, wl, NULL);
+ window_set_name(wl->window, newname);
options_set_number(wl->window->options, "automatic-rename", 0);
server_status_window(wl->window);
+ free(newname);
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c
index ac39f5ce356..426a8db4b49 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.87 2017/08/30 10:33:57 nicm Exp $ */
+/* $OpenBSD: cmd-split-window.c,v 1.88 2018/03/01 12:53:08 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -61,8 +61,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window;
struct window_pane *wp = item->target.wp, *new_wp = NULL;
struct environ *env;
- const char *cmd, *path, *shell, *template, *cwd;
- char **argv, *cause, *new_cause, *cp, *to_free = NULL;
+ const char *cmd, *path, *shell, *template, *tmp;
+ char **argv, *cause, *new_cause, *cp, *cwd;
u_int hlimit;
int argc, size, percentage;
enum layout_type type;
@@ -86,14 +86,12 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
argv = args->argv;
}
- if (args_has(args, 'c')) {
- cwd = args_get(args, 'c');
- to_free = format_single(item, cwd, c, s, NULL, NULL);
- cwd = to_free;
- } else if (item->client != NULL && item->client->session == NULL)
- cwd = item->client->cwd;
+ if ((tmp = args_get(args, 'c')) != NULL)
+ cwd = format_single(item, tmp, c, s, NULL, NULL);
+ else if (item->client != NULL && item->client->session == NULL)
+ cwd = xstrdup(item->client->cwd);
else
- cwd = s->cwd;
+ cwd = xstrdup(s->cwd);
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
@@ -175,7 +173,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
hooks_insert(s->hooks, item, &fs, "after-split-window");
- free(to_free);
+ free(cwd);
return (CMD_RETURN_NORMAL);
error:
@@ -186,6 +184,6 @@ error:
cmdq_error(item, "create pane failed: %s", cause);
free(cause);
- free(to_free);
+ free(cwd);
return (CMD_RETURN_ERROR);
}