df58625ca62ebb6ff5b7730717fdd55afdd28e63
- Author
- Tom Hale <HaleTom@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/safe-paste/safe-paste.plugin.zsh b/plugins/safe-paste/safe-paste.plugin.zsh
2index 75f1791d7003a860476d15c9f75fae60be5456c2..db524538cc4279e17fbc216d1ccee1348ce85623 100644
3--- a/plugins/safe-paste/safe-paste.plugin.zsh
4+++ b/plugins/safe-paste/safe-paste.plugin.zsh
5@@ -1,54 +1,100 @@
6+# A good summary of the zsh 5.1 Bracketed Paste Mode changes is at:
7+# https://archive.zhimingwang.org/blog/2015-09-21-zsh-51-and-bracketed-paste.html
8+
9+# zsh 5.1 (September 2015) introduced built-in support for Bracketed Paste Mode
10+# https://github.com/zsh-users/zsh/blob/68405f31a043bdd5bf338eb06688ed3e1f740937/README#L38-L45
11+#
12+# zsh 5.1 breaks url-quote-magic and other widgets replacing self-insert
13+# zsh-users' bracketed-paste-magic resolves these issues:
14+# https://github.com/zsh-users/zsh/blob/f702e17b14d75aa21bff014168fa9048124db286/Functions/Zle/bracketed-paste-magic#L9-L12
15+
16+# Load bracketed-paste-magic if zsh version is >= 5.1
17+if [[ ${ZSH_VERSION:0:3} -ge 5.1 ]]; then
18+ set zle_bracketed_paste # Explicitly restore this zsh default
19+ autoload -Uz bracketed-paste-magic
20+ zle -N bracketed-paste bracketed-paste-magic
21+ return ### The rest of this file is NOT executed on zsh version >= 5.1 ###
22+fi
23+
24+######################################################################
25+# The rest of this file is ONLY executed if zsh version < 5.1
26+######################################################################
27+
28 # Code from Mikael Magnusson: https://www.zsh.org/mla/users/2011/msg00367.html
29 #
30-# Requires xterm, urxvt, iTerm2 or any other terminal that supports bracketed
31-# paste mode as documented: https://www.xfree86.org/current/ctlseqs.html
32-
33-# create a new keymap to use while pasting
34-bindkey -N paste
35-# make everything in this keymap call our custom widget
36-bindkey -R -M paste "^@"-"\M-^?" paste-insert
37-# these are the codes sent around the pasted text in bracketed
38-# paste mode.
39-# do the first one with both -M viins and -M vicmd in vi mode
40-bindkey '^[[200~' _start_paste
41-bindkey -M paste '^[[201~' _end_paste
42-# insert newlines rather than carriage returns when pasting newlines
43-bindkey -M paste -s '^M' '^J'
44-
45-zle -N _start_paste
46-zle -N _end_paste
47-zle -N zle-line-init _zle_line_init
48-zle -N zle-line-finish _zle_line_finish
49-zle -N paste-insert _paste_insert
50-
51-# switch the active keymap to paste mode
52-function _start_paste() {
53- bindkey -A paste main
54+# Requires xterm, urxvt, iTerm2 or any other terminal that supports
55+# Bracketed Paste Mode as documented:
56+# https://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode
57+#
58+# For tmux, use: bind ] paste-buffer -p
59+#
60+# Additional technical details: https://cirw.in/blog/bracketed-paste
61+
62+# Create a new keymap to use while pasting
63+bindkey -N bracketed-paste
64+# Make everything in this new keymap enqueue characters for pasting
65+bindkey -RM bracketed-paste '\x00-\xFF' bracketed-paste-enqueue
66+# These are the codes sent around the pasted text in bracketed paste mode
67+bindkey -M main '^[[200~' _bracketed_paste_begin
68+bindkey -M bracketed-paste '^[[201~' _bracketed_paste_end
69+# Insert newlines rather than carriage returns when pasting newlines
70+bindkey -M bracketed-paste -s '^M' '^J'
71+
72+zle -N _bracketed_paste_begin
73+zle -N _bracketed_paste_end
74+zle -N bracketed-paste-enqueue _bracketed_paste_enqueue
75+
76+# Attempt to not clobber zle_line_{init,finish}
77+# Use https://github.com/willghatch/zsh-hooks if available
78+if typeset -f hooks-add-hook > /dev/null; then
79+ hooks-add-hook zle_line_init_hook _bracketed_paste_zle_init
80+ hooks-add-hook zle_line_finish_hook _bracketed_paste_zle_finish
81+else
82+ zle -N zle-line-init _bracketed_paste_zle_init
83+ zle -N zle-line-finish _bracketed_paste_zle_finish
84+fi
85+
86+# Switch the active keymap to paste mode
87+_bracketed_paste_begin() {
88+ # Save the bindkey command to restore the active ("main") keymap
89+ # Tokenise the restorative bindkey command into an array
90+ _bracketed_paste_restore_keymap=( ${(z)"$(bindkey -lL main)"} )
91+ bindkey -A bracketed-paste main
92 }
93
94-# go back to our normal keymap, and insert all the pasted text in the
95-# command line. this has the nice effect of making the whole paste be
96+# Go back to our normal keymap, and insert all the pasted text in the
97+# command line. This has the nice effect of making the whole paste be
98 # a single undo/redo event.
99-function _end_paste() {
100-#use bindkey -v here with vi mode probably. maybe you want to track
101-#if you were in ins or cmd mode and restore the right one.
102- bindkey -e
103- LBUFFER+=$_paste_content
104- unset _paste_content