Merge branch 'obsd-master'

Sync from OpenBSD.
pull/1/head
Thomas Adam 2012-12-31 18:50:37 +00:00
commit 675c6b3773
16 changed files with 72 additions and 30 deletions

32
cfg.c
View File

@ -19,6 +19,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -78,8 +79,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
{ {
FILE *f; FILE *f;
u_int n; u_int n;
char *buf, *line, *cause; char *buf, *copy, *line, *cause;
size_t len, newlen; size_t len, oldlen;
struct cmd_list *cmdlist; struct cmd_list *cmdlist;
struct cmd_ctx ctx; struct cmd_ctx ctx;
enum cmd_retval retval; enum cmd_retval retval;
@ -95,21 +96,23 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
line = NULL; line = NULL;
retval = CMD_RETURN_NORMAL; retval = CMD_RETURN_NORMAL;
while ((buf = fgetln(f, &len))) { while ((buf = fgetln(f, &len))) {
/* Trim \n. */
if (buf[len - 1] == '\n') if (buf[len - 1] == '\n')
len--; len--;
log_debug ("%s: %s", path, buf);
/* Current line is the continuation of the previous one. */ /* Current line is the continuation of the previous one. */
if (line != NULL) { if (line != NULL) {
newlen = strlen(line) + len + 1; oldlen = strlen(line);
line = xrealloc(line, 1, newlen); line = xrealloc(line, 1, oldlen + len + 1);
} else { } else {
newlen = len + 1; oldlen = 0;
line = xmalloc(newlen); line = xmalloc(len + 1);
*line = '\0';
} }
/* Append current line to the previous. */ /* Append current line to the previous. */
strlcat(line, buf, newlen); memcpy(line + oldlen, buf, len);
line[oldlen + len] = '\0';
n++; n++;
/* Continuation: get next line? */ /* Continuation: get next line? */
@ -121,18 +124,25 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
if (len > 1 && line[len - 2] != '\\') if (len > 1 && line[len - 2] != '\\')
continue; continue;
} }
buf = line; copy = line;
line = NULL; line = NULL;
/* Skip empty lines. */
buf = copy;
while (isspace((u_char)*buf))
buf++;
if (*buf == '\0')
continue;
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) { if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
free(buf); free(copy);
if (cause == NULL) if (cause == NULL)
continue; continue;
cfg_add_cause(causes, "%s: %u: %s", path, n, cause); cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
free(cause); free(cause);
continue; continue;
} }
free(buf); free(copy);
if (cmdlist == NULL) if (cmdlist == NULL)
continue; continue;

View File

@ -32,7 +32,8 @@ enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_capture_pane_entry = { const struct cmd_entry cmd_capture_pane_entry = {
"capture-pane", "capturep", "capture-pane", "capturep",
"b:E:S:t:", 0, 0, "b:E:S:t:", 0, 0,
"[-b buffer-index] [-E end-line] [-S start-line] [-t target-pane]", "[-b buffer-index] [-E end-line] [-S start-line] "
CMD_TARGET_PANE_USAGE,
0, 0,
NULL, NULL,
NULL, NULL,

View File

@ -39,8 +39,8 @@ void cmd_choose_tree_free(struct window_choose_data *);
const struct cmd_entry cmd_choose_tree_entry = { const struct cmd_entry cmd_choose_tree_entry = {
"choose-tree", NULL, "choose-tree", NULL,
"S:W:swb:c:t:", 0, 1, "S:W:swub:c:t:", 0, 1,
"[-sw] [-b session-template] [-c window template] [-S format] " \ "[-swu] [-b session-template] [-c window template] [-S format] " \
"[-W format] " CMD_TARGET_WINDOW_USAGE, "[-W format] " CMD_TARGET_WINDOW_USAGE,
0, 0,
NULL, NULL,
@ -232,6 +232,9 @@ windows_only:
window_choose_ready(wl->window->active, cur_win, window_choose_ready(wl->window->active, cur_win,
cmd_choose_tree_callback, cmd_choose_tree_free); cmd_choose_tree_callback, cmd_choose_tree_free);
if (args_has(args, 'u'))
window_choose_expand_all(wl->window->active);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@ -32,7 +32,8 @@ enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_display_message_entry = { const struct cmd_entry cmd_display_message_entry = {
"display-message", "display", "display-message", "display",
"c:pt:F:", 0, 1, "c:pt:F:", 0, 1,
"[-p] [-c target-client] [-t target-pane] [-F format] [message]", "[-p] [-c target-client] [-F format] " CMD_TARGET_PANE_USAGE
" [message]",
0, 0,
NULL, NULL,
NULL, NULL,

View File

@ -38,7 +38,7 @@ void cmd_list_panes_window(struct cmd *,
const struct cmd_entry cmd_list_panes_entry = { const struct cmd_entry cmd_list_panes_entry = {
"list-panes", "lsp", "list-panes", "lsp",
"asF:t:", 0, 0, "asF:t:", 0, 0,
"[-as] [-F format] [-t target]", "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
0, 0,
NULL, NULL,
NULL, NULL,

View File

@ -36,8 +36,8 @@ enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_new_session_entry = { const struct cmd_entry cmd_new_session_entry = {
"new-session", "new", "new-session", "new",
"dn:s:t:x:y:", 0, 1, "dn:s:t:x:y:", 0, 1,
"[-d] [-n window-name] [-s session-name] [-t target-session] " "[-d] [-n window-name] [-s session-name] " CMD_TARGET_SESSION_USAGE
"[-x width] [-y height] [command]", " [-x width] [-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON, CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL, NULL,
cmd_new_session_check, cmd_new_session_check,

View File

@ -32,7 +32,7 @@ const struct cmd_entry cmd_new_window_entry = {
"new-window", "neww", "new-window", "neww",
"ac:dF:kn:Pt:", 0, 1, "ac:dF:kn:Pt:", 0, 1,
"[-adkP] [-c start-directory] [-F format] [-n window-name] " "[-adkP] [-c start-directory] [-F format] [-n window-name] "
"[-t target-window] [command]", CMD_TARGET_WINDOW_USAGE " [command]",
0, 0,
NULL, NULL,
NULL, NULL,

View File

@ -35,7 +35,7 @@ void cmd_paste_buffer_filter(struct window_pane *,
const struct cmd_entry cmd_paste_buffer_entry = { const struct cmd_entry cmd_paste_buffer_entry = {
"paste-buffer", "pasteb", "paste-buffer", "pasteb",
"db:prs:t:", 0, 0, "db:prs:t:", 0, 0,
"[-dpr] [-s separator] [-b buffer-index] [-t target-pane]", "[-dpr] [-s separator] [-b buffer-index] " CMD_TARGET_PANE_USAGE,
0, 0,
NULL, NULL,
NULL, NULL,

View File

@ -31,8 +31,8 @@ enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_window_entry = { const struct cmd_entry cmd_select_window_entry = {
"select-window", "selectw", "select-window", "selectw",
"lnpt:", 0, 0, "lnpTt:", 0, 0,
"[-lnp] " CMD_TARGET_WINDOW_USAGE, "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
0, 0,
cmd_select_window_key_binding, cmd_select_window_key_binding,
NULL, NULL,
@ -130,7 +130,17 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
if (wl == NULL) if (wl == NULL)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
if (session_select(s, wl->idx) == 0) /*
* If -T and select-window is invoked on same window as
* current, switch to previous window.
*/
if (args_has(self->args, 'T') && wl == s->curw) {
if (session_last(s) != 0) {
ctx->error(ctx, "no last window");
return (-1);
}
server_redraw_session(s);
} else if (session_select(s, wl->idx) == 0)
server_redraw_session(s); server_redraw_session(s);
} }
recalculate_sizes(); recalculate_sizes();

View File

@ -32,7 +32,7 @@ enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_send_keys_entry = { const struct cmd_entry cmd_send_keys_entry = {
"send-keys", "send", "send-keys", "send",
"lRt:", 0, -1, "lRt:", 0, -1,
"[-lR] [-t target-pane] key ...", "[-lR] " CMD_TARGET_PANE_USAGE " key ...",
0, 0,
NULL, NULL,
NULL, NULL,

View File

@ -34,7 +34,7 @@ const struct cmd_entry cmd_split_window_entry = {
"split-window", "splitw", "split-window", "splitw",
"c:dF:l:hp:Pt:v", 0, 1, "c:dF:l:hp:Pt:v", 0, 1,
"[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] " "[-dhvP] [-c start-directory] [-F format] [-p percentage|-l size] "
"[-t target-pane] [command]", CMD_TARGET_PANE_USAGE " [command]",
0, 0,
cmd_split_window_key_binding, cmd_split_window_key_binding,
NULL, NULL,

4
cmd.c
View File

@ -862,6 +862,10 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
wl = s->curw; wl = s->curw;
else if (winptr[0] == '!' && winptr[1] == '\0') else if (winptr[0] == '!' && winptr[1] == '\0')
wl = TAILQ_FIRST(&s->lastw); wl = TAILQ_FIRST(&s->lastw);
else if (winptr[0] == '^' && winptr[1] == '\0')
wl = RB_MIN(winlinks, &s->windows);
else if (winptr[0] == '$' && winptr[1] == '\0')
wl = RB_MAX(winlinks, &s->windows);
else if (winptr[0] == '+' || winptr[0] == '-') else if (winptr[0] == '+' || winptr[0] == '-')
wl = cmd_find_window_offset(winptr, s, &ambiguous); wl = cmd_find_window_offset(winptr, s, &ambiguous);
else else

View File

@ -17,6 +17,7 @@
*/ */
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/stat.h> #include <sys/stat.h>

19
tmux.1
View File

@ -412,11 +412,15 @@ otherwise the current window in
is chosen. is chosen.
The special character The special character
.Ql \&! .Ql \&!
uses the last (previously current) window, or uses the last (previously current) window,
.Ql ^
selects the highest numbered window,
.Ql $
selects the lowest numbered window, and
.Ql + .Ql +
and and
.Ql - .Ql -
are the next window or the previous window by number. select the next window or the previous window by number.
When the argument does not contain a colon, When the argument does not contain a colon,
.Nm .Nm
first attempts to parse it as window; if that fails, an attempt is made to first attempts to parse it as window; if that fails, an attempt is made to
@ -1130,6 +1134,7 @@ This command works only from inside
.Ic choose-tree .Ic choose-tree
.Op Fl s .Op Fl s
.Op Fl w .Op Fl w
.Op Fl u
.Op Fl b Ar session-template .Op Fl b Ar session-template
.Op Fl c Ar window-template .Op Fl c Ar window-template
.Op Fl S Ar format .Op Fl S Ar format
@ -1155,6 +1160,9 @@ If
.Fl w .Fl w
is given, will show windows. is given, will show windows.
If If
.Fl u
is given, the tree is uncollapsed by default.
If
.Fl b .Fl b
is given, will override the default session command. is given, will override the default session command.
Note that Note that
@ -1643,7 +1651,7 @@ is the same as using the
.Ic last-pane .Ic last-pane
command. command.
.It Xo Ic select-window .It Xo Ic select-window
.Op Fl lnp .Op Fl lnpT
.Op Fl t Ar target-window .Op Fl t Ar target-window
.Xc .Xc
.D1 (alias: Ic selectw ) .D1 (alias: Ic selectw )
@ -1659,6 +1667,11 @@ are equivalent to the
and and
.Ic previous-window .Ic previous-window
commands. commands.
If
.Fl T
is given and the selected window is already the current window,
the command behaves like
.Ic last-window .
.It Xo Ic split-window .It Xo Ic split-window
.Op Fl dhvP .Op Fl dhvP
.Op Fl c Ar start-directory .Op Fl c Ar start-directory

1
tmux.h
View File

@ -2239,6 +2239,7 @@ struct window_choose_data *window_choose_add_session(struct window_pane *,
struct window_choose_data *window_choose_add_item(struct window_pane *, struct window_choose_data *window_choose_add_item(struct window_pane *,
struct cmd_ctx *, struct winlink *, const char *, struct cmd_ctx *, struct winlink *, const char *,
char *, u_int); char *, u_int);
void window_choose_expand_all(struct window_pane *);
/* names.c */ /* names.c */
void queue_window_name(struct window *); void queue_window_name(struct window *);

View File

@ -43,7 +43,6 @@ void window_choose_scroll_down(struct window_pane *);
void window_choose_collapse(struct window_pane *, struct session *); void window_choose_collapse(struct window_pane *, struct session *);
void window_choose_expand(struct window_pane *, struct session *, u_int); void window_choose_expand(struct window_pane *, struct session *, u_int);
void window_choose_collapse_all(struct window_pane *); void window_choose_collapse_all(struct window_pane *);
void window_choose_expand_all(struct window_pane *);
enum window_choose_input_type { enum window_choose_input_type {
WINDOW_CHOOSE_NORMAL = -1, WINDOW_CHOOSE_NORMAL = -1,
@ -118,7 +117,6 @@ window_choose_ready(struct window_pane *wp, u_int cur,
ARRAY_CONCAT(&data->old_list, &data->list); ARRAY_CONCAT(&data->old_list, &data->list);
window_choose_collapse_all(wp); window_choose_collapse_all(wp);
window_choose_redraw_screen(wp);
} }
struct screen * struct screen *