sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

vim-arpeggio.sh (1658B)


      1 #!/bin/bash
      2 
      3 ble-import keymap.vi
      4 
      5 bleopt/declare -v vim_arpeggio_timeoutlen 40
      6 
      7 function ble/lib/vim-arpeggio.sh/bind/.usage {
      8   ble/util/print "usage: ble/lib/vim-arpeggio.sh/bind [-m KEYMAP] -[fxcs@] KEYS COMMAND"
      9   ble/util/print "  KEYS has the form of {mods}{X}{Y}. {mods} are modifiers of the form"
     10   ble/util/print "  /([CSMAsH]-)*/ and {X} and {Y} are alphabets which specify simultaneous"
     11   ble/util/print "  keys."
     12 }
     13 
     14 function ble/lib/vim-arpeggio.sh/bind {
     15   local -a opts=()
     16   if [[ $1 == -m ]]; then
     17     if [[ ! $2 ]]; then
     18       ble/util/print "vim-arpeggio.sh: invalid option argument for \`-m'." >&2
     19       ble/lib/vim-arpeggio.sh/bind/.usage >&2
     20       return 1
     21     fi
     22     ble/array#push opts -m "$2"
     23     shift 2
     24   fi
     25 
     26   local type=$1 keys=$2 cmd=$3
     27   if [[ $type == --help ]]; then
     28     ble/lib/vim-arpeggio.sh/bind/.usage
     29     return 0
     30   elif [[ $type != -[fxcs@] ]]; then
     31     ble/util/print "vim-arpeggio.sh: invalid bind type." >&2
     32     ble/lib/vim-arpeggio.sh/bind/.usage >&2
     33     return 1
     34   fi
     35 
     36   local mods=
     37   if local rex='^(([CSMAsH]-)+)..'; [[ $keys =~ $rex ]]; then
     38     mods=${BASH_REMATCH[1]}
     39     keys=${keys:${#mods}}
     40   fi
     41 
     42   local timeout=$((bleopt_vim_arpeggio_timeoutlen))
     43   ((timeout<0)) && timeout=
     44 
     45   if ((${#keys}==2)); then
     46     local k1=$mods${keys::1} k2=$mods${keys:1:1}
     47     ble-bind "${opts[@]}" "$type" "$k1 $k2" "$cmd"
     48     ble-bind "${opts[@]}" "$type" "$k2 $k1" "$cmd"
     49     ble-bind "${opts[@]}" -T "$k1" "$timeout"
     50     ble-bind "${opts[@]}" -T "$k2" "$timeout"
     51   else
     52     ble/util/print "vim-arpeggio.sh: sorry only 2-key bindings are supported now." >&2
     53     ble/lib/vim-arpeggio.sh/bind/.usage >&2
     54     return 1
     55   fi
     56 }