summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2013-03-25 11:44:00 +0000
committerNicholas Marriott <nicm@openbsd.org>2013-03-25 11:44:00 +0000
commit43fb9835fabee828c46d54b656a90a77eb756384 (patch)
treea6c147a3ad260d52f1f40aa9c8db136bc9b7663a
parent599dd2a56009300df999c54c73aa9e83268809e8 (diff)
Add -P and -F to new-session.
-rw-r--r--cmd-new-session.c50
-rw-r--r--cmd-new-window.c6
-rw-r--r--tmux.h12
3 files changed, 43 insertions, 25 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 1cc6fbab..653db876 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -35,9 +35,9 @@ enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
- "AdDn:s:t:x:y:", 0, 1,
- "[-AdD] [-n window-name] [-s session-name] " CMD_TARGET_SESSION_USAGE
- " [-x width] [-y height] [command]",
+ "AdDF:n:Ps:t:x:y:", 0, 1,
+ "[-AdDP] [-F format] [-n window-name] [-s session-name] "
+ CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL,
cmd_new_session_check,
@@ -55,19 +55,20 @@ cmd_new_session_check(struct args *args)
enum cmd_retval
cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
- struct args *args = self->args;
- struct client *c = cmdq->client;
- struct session *s, *groupwith;
- struct window *w;
- struct environ env;
- struct termios tio, *tiop;
- struct passwd *pw;
- const char *newname, *target, *update, *cwd, *errstr;
- char *cmd, *cause;
- int detached, idx;
- u_int sx, sy;
- int already_attached;
-
+ struct args *args = self->args;
+ struct client *c = cmdq->client;
+ struct session *s, *groupwith;
+ struct window *w;
+ struct environ env;
+ struct termios tio, *tiop;
+ struct passwd *pw;
+ const char *newname, *target, *update, *cwd, *errstr;
+ const char *template;
+ char *cmd, *cause, *cp;
+ int detached, idx;
+ u_int sx, sy;
+ int already_attached;
+ struct format_tree *ft;
newname = args_get(args, 's');
if (newname != NULL) {
@@ -233,6 +234,23 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
if (cfg_finished)
cfg_show_causes(s);
+ /* Print if requested. */
+ if (args_has(args, 'P')) {
+ if ((template = args_get(args, 'F')) == NULL)
+ template = NEW_SESSION_TEMPLATE;
+
+ ft = format_create();
+ if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
+ format_client(ft, c);
+ format_session(ft, s);
+
+ cp = format_expand(ft, template);
+ cmdq_print(cmdq, "%s", cp);
+ free(cp);
+
+ format_free(ft);
+ }
+
if (!detached)
cmdq->client_exit = 0;
return (CMD_RETURN_NORMAL);
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 161dc549..eac0df44 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -46,12 +46,10 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct session *s;
struct winlink *wl;
struct client *c;
- const char *cmd, *cwd;
- const char *template;
- char *cause;
+ const char *cmd, *cwd, *template;
+ char *cause, *cp;
int idx, last, detached;
struct format_tree *ft;
- char *cp;
if (args_has(args, 'a')) {
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
diff --git a/tmux.h b/tmux.h
index afba7804..10da2bee 100644
--- a/tmux.h
+++ b/tmux.h
@@ -159,6 +159,7 @@ extern char **environ;
/* Default templates for break-pane, new-window and split-window. */
#define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
+#define NEW_SESSION_TEMPLATE "#{session_name}:"
#define NEW_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE
#define SPLIT_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE
@@ -780,9 +781,6 @@ struct job {
int fd;
struct bufferevent *event;
- struct bufferevent *out;
- int outdone;
-
void (*callbackfn)(struct job *);
void (*freefn)(void *);
void *data;
@@ -1416,6 +1414,9 @@ struct cmd_q {
struct cmd_q_item *item;
struct cmd *cmd;
+ time_t time;
+ u_int number;
+
void (*emptyfn)(struct cmd_q *);
void *data;
@@ -1611,8 +1612,8 @@ int options_table_find(const char *, const struct options_table_entry **,
/* job.c */
extern struct joblist all_jobs;
-struct job *job_run(
- const char *, void (*)(struct job *), void (*)(void *), void *);
+struct job *job_run(const char *, struct session *,
+ void (*)(struct job *), void (*)(void *), void *);
void job_free(struct job *);
void job_died(struct job *, int);
@@ -1857,6 +1858,7 @@ int cmdq_free(struct cmd_q *);
void printflike2 cmdq_print(struct cmd_q *, const char *, ...);
void printflike2 cmdq_info(struct cmd_q *, const char *, ...);
void printflike2 cmdq_error(struct cmd_q *, const char *, ...);
+int cmdq_guard(struct cmd_q *, const char *);
void cmdq_run(struct cmd_q *, struct cmd_list *);
void cmdq_append(struct cmd_q *, struct cmd_list *);
int cmdq_continue(struct cmd_q *);