diff options
author | 2016-01-31 09:54:46 +0000 | |
---|---|---|
committer | 2016-01-31 09:54:46 +0000 | |
commit | 567cbf69b070ab8c202a67848c3ad8db9cc5f987 (patch) | |
tree | f59fbb6a26d8327a593d3b4a23af26ba864d4e7b | |
parent | Fix new-session with -t after command flags changes, reported by Michael Graczyk. (diff) | |
download | wireguard-openbsd-567cbf69b070ab8c202a67848c3ad8db9cc5f987.tar.xz wireguard-openbsd-567cbf69b070ab8c202a67848c3ad8db9cc5f987.zip |
Support negative trim values (#{=-10:pane_title}) to trim from the end,
suggested by Kevin Brubeck Unhammer.
-rw-r--r-- | usr.bin/tmux/format.c | 14 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 14 |
2 files changed, 18 insertions, 10 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index c8bd2aefe3a..0e83446a345 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.104 2016/01/19 15:59:12 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.105 2016/01/31 09:54:46 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -684,7 +684,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, char *copy, *copy0, *endptr, *ptr, *found, *new, *value; char *from = NULL, *to = NULL; size_t valuelen, newlen, fromlen, tolen, used; - u_long limit = 0; + long limit = 0; int modifiers = 0, brackets; /* Make a copy of the key. */ @@ -696,8 +696,8 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, switch (copy[0]) { case '=': errno = 0; - limit = strtoul(copy + 1, &endptr, 10); - if (errno == ERANGE && limit == ULONG_MAX) + limit = strtol(copy + 1, &endptr, 10); + if (errno == ERANGE && (limit == LONG_MIN || limit == LONG_MAX)) break; if (*endptr != ':') break; @@ -813,10 +813,14 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen, } /* Truncate the value if needed. */ - if (limit != 0) { + if (limit > 0) { new = utf8_trimcstr(value, limit); free(value); value = new; + } else if (limit < 0) { + new = utf8_rtrimcstr(value, -limit); + free(value); + value = new; } /* Expand the buffer and copy in the value. */ diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 4065e9c3be6..849b37e480a 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.478 2016/01/29 11:13:56 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.479 2016/01/31 09:54:46 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 29 2016 $ +.Dd $Mdocdate: January 31 2016 $ .Dt TMUX 1 .Os .Sh NAME @@ -3377,9 +3377,13 @@ if not. A limit may be placed on the length of the resultant string by prefixing it by an .Ql = , -a number and a colon, so -.Ql #{=10:pane_title} -will include at most the first 10 characters of the pane title. +a number and a colon. +Positive numbers count from the start of the string and negative from the end, +so +.Ql #{=5:pane_title} +will include at most the first 5 characters of the pane title, or +.Ql #{=-5:pane_title} +the last 5 characters. Prefixing a time variable with .Ql t: will convert it to a string, so if |