diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-08-24 10:46:02 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2011-08-24 10:46:02 +0000 |
commit | 2638194d986281888258c22490f8087d7b346731 (patch) | |
tree | e32f18a52cc6d5978360fccbeb22b356af116714 /usr.bin | |
parent | 6290d9c8cfb929571530d4febe1af6f51d37c9c5 (diff) |
Support \ for line continuation in the configuration file, from Julius
Plenz.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cfg.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 8 |
2 files changed, 34 insertions, 11 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c index 3957f869550..a8ed42026a9 100644 --- a/usr.bin/tmux/cfg.c +++ b/usr.bin/tmux/cfg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cfg.c,v 1.12 2010/12/29 21:28:32 nicm Exp $ */ +/* $OpenBSD: cfg.c,v 1.13 2011/08/24 10:46:01 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -92,22 +92,37 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) retval = 0; while ((buf = fgetln(f, &len))) { if (buf[len - 1] == '\n') - buf[len - 1] = '\0'; + len--; + + if (line != NULL) + line = xrealloc(line, 1, strlen(line) + len + 1); else { - line = xrealloc(line, 1, len + 1); - memcpy(line, buf, len); - line[len] = '\0'; - buf = line; + line = xmalloc(len + 1); + *line = '\0'; } + + /* Append buffer to line. strncat will terminate. */ + strncat(line, buf, len); n++; + /* Continuation: get next line? */ + len = strlen(line); + if (len > 0 && line[len - 1] == '\\') { + line[len - 1] = '\0'; + continue; + } + buf = line; + line = NULL; + if (cmd_string_parse(buf, &cmdlist, &cause) != 0) { + xfree(buf); if (cause == NULL) continue; cfg_add_cause(causes, "%s: %u: %s", path, n, cause); xfree(cause); continue; - } + } else + xfree(buf); if (cmdlist == NULL) continue; cfg_cause = NULL; @@ -131,12 +146,16 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) retval = 1; cmd_list_free(cmdlist); if (cfg_cause != NULL) { - cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause); + cfg_add_cause( + causes, "%s: %d: %s", path, n, cfg_cause); xfree(cfg_cause); } } - if (line != NULL) + if (line != NULL) { + cfg_add_cause(causes, + "%s: %d: line continuation at end of file", path, n); xfree(line); + } fclose(f); return (retval); diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 284fb9cbd68..c532e624684 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.243 2011/08/24 10:29:57 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.244 2011/08/24 10:46:01 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -491,7 +491,8 @@ $ tmux bind-key F1 set-window-option force-width 81 Multiple commands may be specified together as part of a .Em command sequence . Each command should be separated by spaces and a semicolon; -commands are executed sequentially from left to right. +commands are executed sequentially from left to right and +lines ending with a backslash continue on to the next line. A literal semicolon may be included by escaping it with a backslash (for example, when specifying a command sequence to .Ic bind-key ) . @@ -507,6 +508,9 @@ rename-session -tfirst newname set-window-option -t:0 monitor-activity on new-window ; split-window -d + +bind-key R source-file ~/.tmux.conf \e; \e + display-message "source-file done" .Ed .Pp Or from |