[Pkg-zsh-devel] [PATCH 6/6] Try to bind <mod>-<cursor>

Frank Terbeck ft at bewatermyfriend.org
Mon Mar 5 23:02:12 UTC 2012


First via terminfo, then at best effort.

Signed-off-by: Frank Terbeck <ft at bewatermyfriend.org>
---
 debian/zshrc |   39 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/debian/zshrc b/debian/zshrc
index 4a0bfb4..f98e130 100644
--- a/debian/zshrc
+++ b/debian/zshrc
@@ -24,6 +24,10 @@ then
         Right    "${terminfo[kcuf1]}"
         PageUp   "${terminfo[kpp]}"
         PageDown "${terminfo[knp]}"
+        S-Up     "${terminfo[kUP]}"   A-Up     "${terminfo[kUP3]}"   C-Up     "${terminfo[kUP5]}"
+        S-Down   "${terminfo[kDN]}"   A-Down   "${terminfo[kDN3]}"   C-Down   "${terminfo[kDN5]}"
+        S-Left   "${terminfo[kLFT]}"  A-Left   "${terminfo[kLFT3]}"  C-Left   "${terminfo[kLFT5]}"
+        S-Right  "${terminfo[kRIT]}"  A-Right  "${terminfo[kRIT3]}"  C-Right  "${terminfo[kRIT5]}"
     )
 
     function bind2maps () {
@@ -36,7 +40,12 @@ then
         done
         shift
 
-        sequence="${key[$1]}"
+        if [[ "$1" == "-r" ]]; then
+            shift
+            sequence="$1"
+        else
+            sequence="${key[$1]}"
+        fi
         widget="$2"
 
         [[ -z "$sequence" ]] && return 1
@@ -44,6 +53,21 @@ then
         for i in "${maps[@]}"; do
             bindkey -M "$i" "$sequence" "$widget"
         done
+        return 0
+    }
+
+    bindbesteffort () {
+        local "name=$1" "fb1=$2" "fb2=$3" "emacs=$4" "vi=$5"
+        local i
+
+        bind2maps emacs viins       -- "$name" "$emacs"
+        bind2maps             vicmd -- "$name" "$vi"
+        if [[ "$?" != '0' ]]; then
+            for i in "$fb1" "$fb2"; do
+                bind2maps emacs viins       -- -r "$i" "$emacs"
+                bind2maps             vicmd -- -r "$i" "$vi"
+            done
+        fi
     }
 
     bind2maps emacs             -- Home   beginning-of-line
@@ -60,6 +84,18 @@ then
     bind2maps       viins vicmd -- Left   vi-backward-char
     bind2maps emacs             -- Right  forward-char
     bind2maps       viins vicmd -- Right  vi-forward-char
+    # Some people expect <Modifier>-<CursorKey> combinations to work in
+    # terminals. However most terminals don't disclose the relevant
+    # capabilities in their terminfo entries. For those that do, we'll setup
+    # some of the combinations to word-jumping. For terminals that don't
+    # disclose the required capabilities, we'll try how far some guess-work
+    # brings us.
+    bindbesteffort S-Left  $'\e[1;2D' $'\e[d'              backward-word vi-backward-word
+    bindbesteffort A-Left  $'\e[1;3D' $'\e'"${key[Left]}"  backward-word vi-backward-word
+    bindbesteffort C-Left  $'\e[1;5D' $'\eOd'              backward-word vi-backward-word
+    bindbesteffort S-Right $'\e[1;2C' $'\e[c'              forward-word  vi-forward-word
+    bindbesteffort A-Right $'\e[1;3C' $'\e'"${key[Right]}" forward-word  vi-forward-word
+    bindbesteffort C-Right $'\e[1;5C' $'\eOc'              forward-word  vi-forward-word
 
     # Make sure the terminal is in application mode, when zle is
     # active. Only then are the values from $terminfo valid.
@@ -73,6 +109,7 @@ then
     zle -N zle-line-finish
 
     unfunction bind2maps
+    unfunction bindbesteffort
 
 fi # [[ -z "$DEBIAN_PREVENT_KEYBOARD_CHANGES" ]] && [[ "$TERM" != 'emacs' ]]
 
-- 
1.7.9.188.g12766




More information about the Pkg-zsh-devel mailing list