annotate .shell.d/99.safe-paste.zsh @ 421:9a2541ec4d4d

emacs: call package-initialize in .emacs
author Augie Fackler <raf@durin42.com>
date Tue, 29 Nov 2016 13:29:54 -0500
parents bef29d49d19f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
351
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1 # taken from https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/plugins/safe-paste/safe-paste.plugin.zsh
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2 # Code from Mikael Magnusson: http://www.zsh.org/mla/users/2011/msg00367.html
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 #
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 # Requires xterm, urxvt, iTerm2 or any other terminal that supports bracketed
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 # paste mode as documented: http://www.xfree86.org/current/ctlseqs.html
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 # create a new keymap to use while pasting
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 bindkey -N paste
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 # make everything in this keymap call our custom widget
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 bindkey -R -M paste "^@"-"\M-^?" paste-insert
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 # these are the codes sent around the pasted text in bracketed
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 # paste mode.
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 # do the first one with both -M viins and -M vicmd in vi mode
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 bindkey '^[[200~' _start_paste
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 bindkey -M paste '^[[201~' _end_paste
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 # insert newlines rather than carriage returns when pasting newlines
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 bindkey -M paste -s '^M' '^J'
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 zle -N _start_paste
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 zle -N _end_paste
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 zle -N zle-line-init _zle_line_init
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 zle -N zle-line-finish _zle_line_finish
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 zle -N paste-insert _paste_insert
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
25 # switch the active keymap to paste mode
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
26 function _start_paste() {
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
27 bindkey -A paste main
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
28 }
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
29
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
30 # go back to our normal keymap, and insert all the pasted text in the
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
31 # command line. this has the nice effect of making the whole paste be
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
32 # a single undo/redo event.
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
33 function _end_paste() {
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
34 #use bindkey -v here with vi mode probably. maybe you want to track
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
35 #if you were in ins or cmd mode and restore the right one.
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
36 bindkey -e
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
37 LBUFFER+=$_paste_content
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
38 unset _paste_content
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
39 }
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
40
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
41 function _paste_insert() {
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
42 _paste_content+=$KEYS
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
43 }
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
44
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
45 function _zle_line_init() {
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
46 # Tell terminal to send escape codes around pastes.
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
47 [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM = screen-256color ]] && printf '\e[?2004h'
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
48 }
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
49
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
50 function _zle_line_finish() {
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
51 # Tell it to stop when we leave zle, so pasting in other programs
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
52 # doesn't get the ^[[200~ codes around the pasted text.
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
53 [[ $TERM == rxvt-unicode || $TERM == xterm || $TERM = xterm-256color || $TERM = screen || $TERM = screen-256color ]] && printf '\e[?2004l'
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
54 }
bef29d49d19f safe-paste: adds support for bracketed paste mode to zsh
Augie Fackler <raf@durin42.com>
parents:
diff changeset
55