summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2017-05-29 18:06:35 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2017-05-29 18:06:35 +0000
commitdf3e16ffcc2a17285a16b4d8488b837148d5e8b3 (patch)
tree2877ae5fb054d9cf2469d83a6b93c1debfdfcafa /usr.bin/tmux
parenteff3b16733b1325c1e914222d399369cc8377c38 (diff)
Add ||, && format operators and C: to search pane content.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-find-window.c4
-rw-r--r--usr.bin/tmux/format.c52
-rw-r--r--usr.bin/tmux/tmux.124
-rw-r--r--usr.bin/tmux/tmux.h5
-rw-r--r--usr.bin/tmux/window.c28
5 files changed, 89 insertions, 24 deletions
diff --git a/usr.bin/tmux/cmd-find-window.c b/usr.bin/tmux/cmd-find-window.c
index a117b622042..68a52f3ee4c 100644
--- a/usr.bin/tmux/cmd-find-window.c
+++ b/usr.bin/tmux/cmd-find-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-find-window.c,v 1.41 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-find-window.c,v 1.42 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -122,7 +122,7 @@ cmd_find_window_match(struct cmd_find_window_list *find_list,
}
if (match_flags & CMD_FIND_WINDOW_BY_CONTENT &&
- (sres = window_pane_search(wp, str, &line)) != NULL) {
+ (sres = window_pane_search_old(wp, str, &line)) != NULL) {
xasprintf(&find_data->list_ctx,
"pane %u line %u: \"%s\"", i - 1, line + 1, sres);
free(sres);
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index fd20dfacfff..7ce43b6ee49 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.139 2017/05/29 15:43:48 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.140 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -848,19 +848,17 @@ format_true(const char *s)
return (0);
}
-/*
- * Replace a key/value pair in buffer. #{blah} is expanded directly,
- * #{?blah,a,b} is replace with a if blah exists and is nonzero else b.
- */
+/* Replace a key. */
static int
format_replace(struct format_tree *ft, const char *key, size_t keylen,
char **buf, size_t *len, size_t *off)
{
- char *copy, *copy0, *endptr, *ptr, *found, *new, *value;
- char *from = NULL, *to = NULL, *left, *right;
- size_t valuelen, newlen, fromlen, tolen, used;
- long limit = 0;
- int modifiers = 0, compare = 0;
+ struct window_pane *wp = ft->wp;
+ char *copy, *copy0, *endptr, *ptr, *found, *new;
+ char *value, *from = NULL, *to = NULL, *left, *right;
+ size_t valuelen, newlen, fromlen, tolen, used;
+ long limit = 0;
+ int modifiers = 0, compare = 0, search = 0;
/* Make a copy of the key. */
copy0 = copy = xmalloc(keylen + 1);
@@ -875,6 +873,24 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
compare = -2;
copy += 2;
break;
+ case 'C':
+ if (copy[1] != ':')
+ break;
+ search = 1;
+ copy += 2;
+ break;
+ case '|':
+ if (copy[1] != '|' || copy[2] != ':')
+ break;
+ compare = -3;
+ copy += 3;
+ break;
+ case '&':
+ if (copy[1] != '&' || copy[2] != ':')
+ break;
+ compare = -4;
+ copy += 3;
+ break;
case '!':
if (copy[1] == '=' && copy[2] == ':') {
compare = -1;
@@ -940,13 +956,25 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
}
/* Is this a comparison or a conditional? */
- if (compare != 0) {
+ if (search) {
+ /* Search in pane. */
+ if (wp == NULL)
+ value = xstrdup("0");
+ else
+ xasprintf(&value, "%u", window_pane_search(wp, copy));
+ } else if (compare != 0) {
/* Comparison: compare comma-separated left and right. */
if (format_choose(copy, &left, &right) != 0)
goto fail;
left = format_expand(ft, left);
right = format_expand(ft, right);
- if (compare == 1 && strcmp(left, right) == 0)
+ if (compare == -3 &&
+ (format_true(left) || format_true(right)))
+ value = xstrdup("1");
+ else if (compare == -4 &&
+ (format_true(left) && format_true(right)))
+ value = xstrdup("1");
+ else if (compare == 1 && strcmp(left, right) == 0)
value = xstrdup("1");
else if (compare == -1 && strcmp(left, right) != 0)
value = xstrdup("1");
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index cbc0acfaaad..d6cba360db1 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.553 2017/05/29 15:43:48 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.554 2017/05/29 18:06:34 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -3430,7 +3430,7 @@ is enabled, or
.Ql no
if not.
.Pp
-Simple comparisons may be expressed by prefixing two comma-separated
+Comparisons may be expressed by prefixing two comma-separated
alternatives by
.Ql ==
or
@@ -3443,14 +3443,26 @@ will be replaced by
if running on
.Ql myhost ,
otherwise by
-.Ql 0.
+.Ql 0 .
An
.Ql m
-specifies a
+specifies an
.Xr fnmatch 3
-comparison - the first argument is the pattern and the second the string to
-compare. For example,
+comparison where the first argument is the pattern and the second the string to
+compare, for example
.Ql #{m:*foo*,#{host}} .
+.Ql ||
+and
+.Ql &&
+evaluate to true if either or both of two comma-separated alternatives are
+true, for example
+.Ql #{||,#{pane_in_mode},#{alternate_on}} .
+A
+.Ql C
+performs a search for an
+.Xr fnmatch 3
+pattern in the pane content and evaluates to zero if not found, or a line
+number if found.
.Pp
A limit may be placed on the length of the resultant string by prefixing it
by an
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 10e2904b736..2cc405588bf 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.770 2017/05/17 15:20:23 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.771 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2121,7 +2121,8 @@ void window_pane_key(struct window_pane *, struct client *,
struct session *, key_code, struct mouse_event *);
int window_pane_outside(struct window_pane *);
int window_pane_visible(struct window_pane *);
-char *window_pane_search(struct window_pane *, const char *,
+u_int window_pane_search(struct window_pane *, const char *);
+char *window_pane_search_old(struct window_pane *, const char *,
u_int *);
const char *window_printable_flags(struct winlink *);
struct window_pane *window_pane_find_up(struct window_pane *);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 3f2d293f0fe..28110f02ce1 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.194 2017/05/12 10:45:38 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.195 2017/05/29 18:06:34 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1267,8 +1267,32 @@ window_pane_visible(struct window_pane *wp)
return (!window_pane_outside(wp));
}
+u_int
+window_pane_search(struct window_pane *wp, const char *searchstr)
+{
+ struct screen *s = &wp->base;
+ char *newsearchstr, *line;
+ u_int i;
+
+ xasprintf(&newsearchstr, "*%s*", searchstr);
+
+ for (i = 0; i < screen_size_y(s); i++) {
+ line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
+ if (fnmatch(newsearchstr, line, 0) == 0) {
+ free(line);
+ break;
+ }
+ free(line);
+ }
+
+ free(newsearchstr);
+ if (i == screen_size_y(s))
+ return (0);
+ return (i + 1);
+}
+
char *
-window_pane_search(struct window_pane *wp, const char *searchstr,
+window_pane_search_old(struct window_pane *wp, const char *searchstr,
u_int *lineno)
{
struct screen *s = &wp->base;