version 1.12, 2010/01/19 21:27:47 |
version 1.13, 2010/03/27 11:46:58 |
|
|
char *target; |
char *target; |
char *name; |
char *name; |
char *cmd; |
char *cmd; |
|
int flag_insert_after; |
int flag_detached; |
int flag_detached; |
int flag_kill; |
int flag_kill; |
}; |
}; |
|
|
const struct cmd_entry cmd_new_window_entry = { |
const struct cmd_entry cmd_new_window_entry = { |
"new-window", "neww", |
"new-window", "neww", |
"[-dk] [-n window-name] [-t target-window] [command]", |
"[-adk] [-n window-name] [-t target-window] [command]", |
0, "", |
0, "", |
cmd_new_window_init, |
cmd_new_window_init, |
cmd_new_window_parse, |
cmd_new_window_parse, |
|
|
data->target = NULL; |
data->target = NULL; |
data->name = NULL; |
data->name = NULL; |
data->cmd = NULL; |
data->cmd = NULL; |
|
data->flag_insert_after = 0; |
data->flag_detached = 0; |
data->flag_detached = 0; |
data->flag_kill = 0; |
data->flag_kill = 0; |
} |
} |
|
|
self->entry->init(self, KEYC_NONE); |
self->entry->init(self, KEYC_NONE); |
data = self->data; |
data = self->data; |
|
|
while ((opt = getopt(argc, argv, "dkt:n:")) != -1) { |
while ((opt = getopt(argc, argv, "adkt:n:")) != -1) { |
switch (opt) { |
switch (opt) { |
|
case 'a': |
|
data->flag_insert_after = 1; |
|
break; |
case 'd': |
case 'd': |
data->flag_detached = 1; |
data->flag_detached = 1; |
break; |
break; |
|
|
struct session *s; |
struct session *s; |
struct winlink *wl; |
struct winlink *wl; |
char *cmd, *cwd, *cause; |
char *cmd, *cwd, *cause; |
int idx; |
int idx, last; |
|
|
if (data == NULL) |
if (data == NULL) |
return (0); |
return (0); |
|
|
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2) |
if (data->flag_insert_after) { |
return (-1); |
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL) |
|
return (-1); |
|
idx = wl->idx + 1; |
|
|
|
/* Find the next free index. */ |
|
for (last = idx; last < INT_MAX; last++) { |
|
if (winlink_find_by_index(&s->windows, last) == NULL) |
|
break; |
|
} |
|
if (last == INT_MAX) { |
|
ctx->error(ctx, "no free window indexes"); |
|
return (-1); |
|
} |
|
|
|
/* Move everything from last - 1 to idx up a bit. */ |
|
for (; last > idx; last--) { |
|
wl = winlink_find_by_index(&s->windows, last - 1); |
|
server_link_window(s, wl, s, last, 0, 0, NULL); |
|
server_unlink_window(s, wl); |
|
} |
|
} else { |
|
if ((idx = cmd_find_index(ctx, data->target, &s)) == -2) |
|
return (-1); |
|
} |
|
|
wl = NULL; |
wl = NULL; |
if (idx != -1) |
if (idx != -1) |