Bracketed paste mode support?
mash opened this issue · comments
What is the peco version, OS, architecture?
peco version v0.5.0
macOS 10.12.3
zsh 5.2 (x86_64-apple-darwin16.0)
tmux 2.3
Abstract
When pasting into peco (in this case "test"), I see:
The extra [200~
and [201~
limits the input, which is what I don't want.
When pasting the same into zsh directly, zsh will highlight the pasted "test".
Discussion
Looks like it's related to Bracketed paste mode: https://cirw.in/blog/bracketed-paste
Is this an issue in peco or a FAQ related to zsh/tmux?
beats me... I use zsh, but not tmux, and have never encountered this issue... so I'm guessing tmux?
hmm weird.
Turns out, the issue happens without tmux,
when using following zsh function and type Ctrl+r
function peco-history-selection() {
BUFFER=`history -n 1 | tail -r | awk '!a[$0]++' | peco`
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N peco-history-selection
bindkey '^R' peco-history-selection
but when directly running
% history -n 1 | tail -r | awk '!a[$0]++' | peco
and pasting some string works as expected.
So it should be my zsh config causing this?
Ha! I was able to reproduce it using your function
But I still have absolutely no clue why this happens. I need somebody with more terminal-fu to prod me to look at the right direction.
It seems not to be a peco issue.
In zsh 5.1 or later, it seems that "bracketed paste mode" works by default. This causes only within zle
widget.
https://github.com/zsh-users/zsh/blob/68405f31a043bdd5bf338eb06688ed3e1f740937/README#L38-L45
Calling unset zle_bracketed_paste
seems to avoid this problem.
Yeah, that seems to work for me. @mash if it works out, it would be great if you could create a FAQ entry for this
Here you go.
After some research, unsetting zle_bracketed_paste globally didn't feel right for me, because it has it's own purposes, ex: safe when pasting multiple lines in zsh.
So I came up with following snippet, which early exits from bracketed paste mode.
function peco-history-selection() {
if (($+zle_bracketed_paste)); then
print $zle_bracketed_paste[2]
fi
BUFFER=`history -n 1 | tail -r | awk '!a[$0]++' | peco`
CURSOR=$#BUFFER
zle reset-prompt
}
zle -N peco-history-selection
bindkey '^R' peco-history-selection
closing.