Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. # add this to your .zshrc
  2.  
  3. r-delregion() {
  4. if ((REGION_ACTIVE)) then
  5. zle kill-region
  6. else
  7. local widget_name=$1
  8. shift
  9. zle $widget_name -- $@
  10. fi
  11. }
  12.  
  13. r-deselect() {
  14. ((REGION_ACTIVE = 0))
  15. local widget_name=$1
  16. shift
  17. zle $widget_name -- $@
  18. }
  19.  
  20. r-select() {
  21. ((REGION_ACTIVE)) || zle set-mark-command
  22. local widget_name=$1
  23. shift
  24. zle $widget_name -- $@
  25. }
  26.  
  27. r-copy-to-xclip() {
  28. [[ "$REGION_ACTIVE" -ne 0 ]] && zle copy-region-as-kill
  29. printf $CUTBUFFER | clip.exe
  30. }
  31.  
  32. for key kcap seq mode widget (
  33. sleft kLFT $'\e[1;2D' select backward-char
  34. sright kRIT $'\e[1;2C' select forward-char
  35. sup kri $'\e[1;2A' select up-line-or-history
  36. sdown kind $'\e[1;2B' select down-line-or-history
  37.  
  38. send kEND $'\E[1;2F' select end-of-line
  39. send2 x $'\E[4;2~' select end-of-line
  40.  
  41. shome kHOM $'\E[1;2H' select beginning-of-line
  42. shome2 x $'\E[1;2~' select beginning-of-line
  43.  
  44. left kcub1 $'\EOD' deselect backward-char
  45. right kcuf1 $'\EOC' deselect forward-char
  46.  
  47. end kend $'\EOF' deselect end-of-line
  48. end2 x $'\E4~' deselect end-of-line
  49.  
  50. home khome $'\EOH' deselect beginning-of-line
  51. home2 x $'\E1~' deselect beginning-of-line
  52.  
  53. csleft x $'\E[1;6D' select backward-word
  54. csright x $'\E[1;6C' select forward-word
  55. csend x $'\E[1;6F' select end-of-line
  56. cshome x $'\E[1;6H' select beginning-of-line
  57.  
  58. cleft x $'\E[1;5D' deselect backward-word
  59. cright x $'\E[1;5C' deselect forward-word
  60.  
  61. del kdch1 $'\E[3~' delregion delete-char
  62. bs x $'^?' delregion backward-delete-char
  63. ) {
  64. eval "key-$key() {
  65. r-$mode $widget \$@
  66. }"
  67. zle -N key-$key
  68. bindkey ${terminfo[$kcap]-$seq} key-$key
  69. }
  70.  
  71. # bind CTRL+C to copy to the clipboard; we don't want to use the native Windows Terminal
  72. # "copy" because it won't work for selections done via zsh on the command line. You can still
  73. # use Windows Terminal functionality for mouse-selecting blocks of text, etc. However
  74. # we still use native pasting from Windows Terminal so it works consistently everywhere
  75.  
  76. zle -N r-copy-to-xclip
  77. bindkey "^C" r-copy-to-xclip
  78.  
  79. # this unbinds ^C before a command is executed (binds to ^Y instead, change to suit yior taste),
  80. # so it will cause an interrupt as expected unless a command line is being edited (when it will
  81. # act as "copy").
  82.  
  83. preexec() {
  84. stty intr \^C
  85. }
  86.  
  87. precmd() {
  88. stty intr \^Y
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement