diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2016-10-21 13:52:00 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2016-10-21 13:52:00 +0000 |
commit | a8a69f43ac019b3ce61dc15893d6aa904b39c861 (patch) | |
tree | d0741af3923e43dda7993eac941da6c9f866a9fa /usr.bin | |
parent | b7593d08857a9a266f96981837f3255fac7cf385 (diff) |
Add %%% to substitute with quotes escaped (convert " to \"). Use this
for the prompts in copy mode. Fixes problems with jumping to ' reported
by Theo Buehler.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd.c | 20 | ||||
-rw-r--r-- | usr.bin/tmux/key-bindings.c | 26 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 10 |
3 files changed, 34 insertions, 22 deletions
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c index c2d50f8ed77..32e9c0f67ba 100644 --- a/usr.bin/tmux/cmd.c +++ b/usr.bin/tmux/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.126 2016/10/16 19:04:05 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.127 2016/10/21 13:51:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -653,8 +653,8 @@ char * cmd_template_replace(const char *template, const char *s, int idx) { char ch, *buf; - const char *ptr; - int replaced; + const char *ptr, *cp; + int replaced, quoted; size_t len; if (strchr(template, '%') == NULL) @@ -676,9 +676,17 @@ cmd_template_replace(const char *template, const char *s, int idx) } ptr++; - len += strlen(s); - buf = xrealloc(buf, len + 1); - strlcat(buf, s, len + 1); + quoted = (*ptr == '%'); + if (quoted) + ptr++; + + buf = xrealloc(buf, len + (strlen(s) * 2) + 1); + for (cp = s; *cp != '\0'; cp++) { + if (quoted && *cp == '"') + buf[len++] = '\\'; + buf[len++] = *cp; + } + buf[len] = '\0'; continue; } buf = xrealloc(buf, len + 2); diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c index 04d17a7a68c..8d8a4a67ba7 100644 --- a/usr.bin/tmux/key-bindings.c +++ b/usr.bin/tmux/key-bindings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: key-bindings.c,v 1.63 2016/10/19 09:24:57 nicm Exp $ */ +/* $OpenBSD: key-bindings.c,v 1.64 2016/10/21 13:51:59 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -242,23 +242,23 @@ key_bindings_init(void) "bind -Tcopy-mode C-k send -X copy-end-of-line", "bind -Tcopy-mode C-n send -X cursor-down", "bind -Tcopy-mode C-p send -X cursor-up", - "bind -Tcopy-mode C-r command-prompt -p'search up' \"send -X search-backward '%%'\"", - "bind -Tcopy-mode C-s command-prompt -p'search down' \"send -X search-forward '%%'\"", + "bind -Tcopy-mode C-r command-prompt -p'search up' \"send -X search-backward \\\"%%%\\\"\"", + "bind -Tcopy-mode C-s command-prompt -p'search down' \"send -X search-forward \\\"%%%\\\"\"", "bind -Tcopy-mode C-v send -X page-down", "bind -Tcopy-mode C-w send -X copy-selection-and-cancel", "bind -Tcopy-mode Escape send -X cancel", "bind -Tcopy-mode Space send -X page-down", "bind -Tcopy-mode , send -X jump-reverse", "bind -Tcopy-mode \\; send -X jump-again", - "bind -Tcopy-mode F command-prompt -1p'jump backward' \"send -X jump-backward '%%'\"", + "bind -Tcopy-mode F command-prompt -1p'jump backward' \"send -X jump-backward \\\"%%%\\\"\"", "bind -Tcopy-mode N send -X search-reverse", "bind -Tcopy-mode R send -X rectangle-toggle", - "bind -Tcopy-mode T command-prompt -1p'jump to backward' \"send -X jump-to-backward '%%'\"", - "bind -Tcopy-mode f command-prompt -1p'jump forward' \"send -X jump-forward '%%'\"", + "bind -Tcopy-mode T command-prompt -1p'jump to backward' \"send -X jump-to-backward \\\"%%%\\\"\"", + "bind -Tcopy-mode f command-prompt -1p'jump forward' \"send -X jump-forward \\\"%%%\\\"\"", "bind -Tcopy-mode g command-prompt -p'goto line' \"send -X goto-line '%%'\"", "bind -Tcopy-mode n send -X search-again", "bind -Tcopy-mode q send -X cancel", - "bind -Tcopy-mode t command-prompt -1p'jump to forward' \"send -X jump-to-forward '%%'\"", + "bind -Tcopy-mode t command-prompt -1p'jump to forward' \"send -X jump-to-forward \\\"%%%\\\"\"", "bind -Tcopy-mode MouseDrag1Pane send -X begin-selection", "bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection-and-cancel", "bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up", @@ -310,7 +310,7 @@ key_bindings_init(void) "bind -Tcopy-mode-vi Space send -X begin-selection", "bind -Tcopy-mode-vi '$' send -X end-of-line", "bind -Tcopy-mode-vi , send -X jump-reverse", - "bind -Tcopy-mode-vi / command-prompt -p'search down' \"send -X search-forward '%%'\"", + "bind -Tcopy-mode-vi / command-prompt -p'search down' \"send -X search-forward \\\"%%%\\\"\"", "bind -Tcopy-mode-vi 0 send -X start-of-line", "bind -Tcopy-mode-vi 1 command-prompt -Np'repeat' -I1 \"send -N '%%'\"", "bind -Tcopy-mode-vi 2 command-prompt -Np'repeat' -I2 \"send -N '%%'\"", @@ -323,12 +323,12 @@ key_bindings_init(void) "bind -Tcopy-mode-vi 9 command-prompt -Np'repeat' -I9 \"send -N '%%'\"", "bind -Tcopy-mode-vi : command-prompt -p'goto line' \"send -X goto-line '%%'\"", "bind -Tcopy-mode-vi \\; send -X jump-again", - "bind -Tcopy-mode-vi ? command-prompt -p'search up' \"send -X search-backward '%%'\"", + "bind -Tcopy-mode-vi ? command-prompt -p'search up' \"send -X search-backward \\\"%%%\\\"\"", "bind -Tcopy-mode-vi A send -X append-selection-and-cancel", "bind -Tcopy-mode-vi B send -X previous-space", "bind -Tcopy-mode-vi D send -X copy-end-of-line", "bind -Tcopy-mode-vi E send -X next-space-end", - "bind -Tcopy-mode-vi F command-prompt -1p'jump backward' \"send -X jump-backward '%%'\"", + "bind -Tcopy-mode-vi F command-prompt -1p'jump backward' \"send -X jump-backward \\\"%%%\\\"\"", "bind -Tcopy-mode-vi G send -X history-bottom", "bind -Tcopy-mode-vi H send -X top-line", "bind -Tcopy-mode-vi J send -X scroll-down", @@ -336,13 +336,13 @@ key_bindings_init(void) "bind -Tcopy-mode-vi L send -X bottom-line", "bind -Tcopy-mode-vi M send -X middle-line", "bind -Tcopy-mode-vi N send -X search-reverse", - "bind -Tcopy-mode-vi T command-prompt -1p'jump to backward' \"send -X jump-to-backward '%%'\"", + "bind -Tcopy-mode-vi T command-prompt -1p'jump to backward' \"send -X jump-to-backward \\\"%%%\\\"\"", "bind -Tcopy-mode-vi V send -X select-line", "bind -Tcopy-mode-vi W send -X next-space", "bind -Tcopy-mode-vi ^ send -X back-to-indentation", "bind -Tcopy-mode-vi b send -X previous-word", "bind -Tcopy-mode-vi e send -X next-word-end", - "bind -Tcopy-mode-vi f command-prompt -1p'jump forward' \"send -X jump-forward '%%'\"", + "bind -Tcopy-mode-vi f command-prompt -1p'jump forward' \"send -X jump-forward \\\"%%%\\\"\"", "bind -Tcopy-mode-vi g send -X history-top", "bind -Tcopy-mode-vi h send -X cursor-left", "bind -Tcopy-mode-vi j send -X cursor-down", @@ -351,7 +351,7 @@ key_bindings_init(void) "bind -Tcopy-mode-vi n send -X search-again", "bind -Tcopy-mode-vi o send -X other-end", "bind -Tcopy-mode-vi q send -X cancel", - "bind -Tcopy-mode-vi t command-prompt -1p'jump to forward' \"send -X jump-to-forward '%%'\"", + "bind -Tcopy-mode-vi t command-prompt -1p'jump to forward' \"send -X jump-to-forward \\\"%%%\\\"\"", "bind -Tcopy-mode-vi v send -X rectangle-toggle", "bind -Tcopy-mode-vi w send -X next-word", "bind -Tcopy-mode-vi { send -X previous-paragraph", diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 782a0c478b8..819d5acd68f 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.512 2016/10/18 19:25:26 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.513 2016/10/21 13:51:59 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: October 18 2016 $ +.Dd $Mdocdate: October 21 2016 $ .Dt TMUX 1 .Os .Sh NAME @@ -3147,6 +3147,7 @@ option. .Xc If this option is set, searches will wrap around the end of the pane contents. The default is on. +.Pp .It Xo Ic xterm-keys .Op Ic on | off .Xc @@ -3157,7 +3158,6 @@ will generate function key sequences; these have a number included to indicate modifiers such as Shift, Alt or Ctrl. The default is off. -.Pp .El .It Xo Ic show-options .Op Fl gqsvw @@ -3770,6 +3770,10 @@ Up to nine prompt responses may be replaced to .Ql %9 .Pc . +.Ql %%% +is like +.Ql %% +but any quotation marks are escaped. .Pp .Fl 1 makes the prompt only accept one key press, in this case the resulting input |