new functions taken from grml, to get a nicer keybinding setup
authorJoerg Jaspert <joerg@debian.org>
Thu, 4 Apr 2013 22:28:55 +0000 (00:28 +0200)
committerJoerg Jaspert <joerg@debian.org>
Thu, 4 Apr 2013 22:28:55 +0000 (00:28 +0200)
.zsh/05_Functions.zsh

index f91375b..0c4e349 100644 (file)
@@ -140,6 +140,50 @@ function Status Start Stop Restart Reload {
         sudo /etc/init.d/${script} ${0:l}
     }
 }
+
+# copied from grml
+function zrcgotwidget() {
+    (( ${+widgets[$1]} ))
+}
+
+# copied from grml
+function zrcgotkeymap() {
+    [[ -n ${(M)keymaps:#$1} ]]
+}
+
+# copied from grml
+function zrcbindkey() {
+    if (( ARGC )) && zrcgotwidget ${argv[-1]}; then
+        bindkey "$@"
+    fi
+}
+
+# copied from grml
+function bind2maps () {
+    local i sequence widget
+    local -a maps
+
+    while [[ "$1" != "--" ]]; do
+        maps+=( "$1" )
+        shift
+    done
+    shift
+
+    if [[ "$1" == "-s" ]]; then
+        shift
+        sequence="$1"
+    else
+        sequence="${key[$1]}"
+    fi
+    widget="$2"
+
+    [[ -z "$sequence" ]] && return 1
+
+    for i in "${maps[@]}"; do
+        zrcbindkey -M "$i" "$sequence" "$widget"
+    done
+}
+
 # move cursor between chars when typing '', "", (), [], and {}
 magic-single-quotes() { if [[ $LBUFFER[-1] == \' ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };
 magic-double-quotes() { if [[ $LBUFFER[-1] == \" ]]; then zle self-insert; zle .backward-char; else zle self-insert; fi };