hlissner / zsh-autopair

Auto-close and delete matching delimiters in zsh
MIT License
506 stars 37 forks source link

Brackets added to pasted input #40

Open typkrft opened 1 month ago

typkrft commented 1 month ago

What would you like to know?

If i were to paste something like

if [[ -z "${DEPLOY_ENV}" ]]; then
  MY_SCRIPT_VARIABLE="Some default value because DEPLOY_ENV is undefined"
else
  MY_SCRIPT_VARIABLE="${DEPLOY_ENV}"
fi

the output ends up as

if [[ -z "${DEPLOY_ENV}" ]]; then ]]
  MY_SCRIPT_VARIABLE="Some default value because DEPLOY_ENV is undefined"
else
  MY_SCRIPT_VARIABLE="${DEPLOY_ENV}"
fi

Autopair seems to add additional brackets to what I'm pasting. Is there away curtail this behavior. I don't generally paste a lot of code snippets like that into my terminal to begin with, so it's not a big deal so I thought I'd ask. I'm not sure how terminal emulators handle pasting, but I've seen the same behavior in kitty and wezterm.

typkrft commented 1 month ago

For anyone that runs into this. My current solution

kitty.conf

# Unbind cmd+v - paste
map cmd+v no_op
# In zshrc
function _paste_without_brackets() {
    text=$(printf "%s\n" "$(pbpaste)")
    LBUFFER+="$text"
}
zle -N _paste_without_brackets
bindkey '^[[118;9u' _paste_without_brackets
hlissner commented 1 month ago

How about enabling bracketed-paste-magic (available in ZSH 5.1+)?

autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic
typkrft commented 1 month ago

I suspect something is going on with kitty processing it. Pasting the above example with your suggestion in place, didn't work for me. However, if I start a new session with zsh --no-rcs it does work. I tried disabling shell integration per Kitty's docs, but to no avail. I very much appreciate your response, on a Sunday no less, and the work you do for the community. Feel free to close this, but I'll come back and report for posterity, when I've identified what's going on.

Sorry my brain must have been turned off when I wrote this. It's not kitty. This only occurs when autopair is loaded. Turning on or off bracketed magic doesn't seem to have any effect for me on this issue. With only autopair loaded and no other configuration applied.