File: vim-arpeggio.sh

package info (click to toggle)
ble.sh 0.4.0~git20250806.8060b7a-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,744 kB
  • sloc: sh: 72,358; awk: 1,316; cpp: 750; ansic: 186; javascript: 43; makefile: 35
file content (56 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash

ble-import keymap.vi

bleopt/declare -v vim_arpeggio_timeoutlen 40

function ble/lib/vim-arpeggio.sh/bind/.usage {
  ble/util/print "usage: ble/lib/vim-arpeggio.sh/bind [-m KEYMAP] -[fxcs@] KEYS COMMAND"
  ble/util/print "  KEYS has the form of {mods}{X}{Y}. {mods} are modifiers of the form"
  ble/util/print "  /([CSMAsH]-)*/ and {X} and {Y} are alphabets which specify simultaneous"
  ble/util/print "  keys."
}

function ble/lib/vim-arpeggio.sh/bind {
  local -a opts=()
  if [[ $1 == -m ]]; then
    if [[ ! $2 ]]; then
      ble/util/print "vim-arpeggio.sh: invalid option argument for \`-m'." >&2
      ble/lib/vim-arpeggio.sh/bind/.usage >&2
      return 1
    fi
    ble/array#push opts -m "$2"
    shift 2
  fi

  local type=$1 keys=$2 cmd=$3
  if [[ $type == --help ]]; then
    ble/lib/vim-arpeggio.sh/bind/.usage
    return 0
  elif [[ $type != -[fxcs@] ]]; then
    ble/util/print "vim-arpeggio.sh: invalid bind type." >&2
    ble/lib/vim-arpeggio.sh/bind/.usage >&2
    return 1
  fi

  local mods=
  if local rex='^(([CSMAsH]-)+)..'; [[ $keys =~ $rex ]]; then
    mods=${BASH_REMATCH[1]}
    keys=${keys:${#mods}}
  fi

  local timeout=$((bleopt_vim_arpeggio_timeoutlen))
  ((timeout<0)) && timeout=

  if ((${#keys}==2)); then
    local k1=$mods${keys::1} k2=$mods${keys:1:1}
    ble-bind "${opts[@]}" "$type" "$k1 $k2" "$cmd"
    ble-bind "${opts[@]}" "$type" "$k2 $k1" "$cmd"
    ble-bind "${opts[@]}" -T "$k1" "$timeout"
    ble-bind "${opts[@]}" -T "$k2" "$timeout"
  else
    ble/util/print "vim-arpeggio.sh: sorry only 2-key bindings are supported now." >&2
    ble/lib/vim-arpeggio.sh/bind/.usage >&2
    return 1
  fi
}