aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bindings.sh
blob: c6b44e827cfb4e57598c461c389e5f54f540f532 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash

# source this file to load key bindings for ariketa

# alt-w:
# clear screen and go back to previous example
_binding_alt_w=(
    '"\ew":"'             #alt-w
    '\C-a\C-k'            #clear line
    '$(( _I > 0 && _I-- ))' #decrement unless we've bottomed out
    '\e\C-e\C-a\C-k'      #interpolate to run decrement above and clear the line
    '\\\n\C-l'            #bring us down onto a newline and clear screen
    '\"$(_example.unpack \"${_examples[$_I]}\")\"' #pull the current example
    '\e\C-e"'             #interpolate
    )

# alt-W:
# go back to previous example without clearing the screen
_binding_alt_W=(
    '"\eW":"'             #alt-W
    '\C-a\C-k'            #clear line
    '$(( _I > 0 && _I-- ))' #decrement unless we've bottomed out
    '\e\C-e\C-a\C-k'      #interpolate to run decrement above and clear the line
    '\\\n'                #bring us down onto a newline
    '\"$(_example.unpack \"${_examples[$_I]}\")\"' #pull the current example
    '\e\C-e"'             #interpolate
    )

# alt-a:
# clear screen and provide current example again without advancing
_binding_alt_a=(
    '"\ea":"'             #alt-a
    '\C-a\C-k'            #clear line
    '\\\n\C-l'            #bring us down onto a newline and clear screen
    '\"$(_example.unpack \"${_examples[$_I]}\")\"' #pull the current example
    '\e\C-e"'             #interpolate
    )

# alt-A:
# provide current example again without advancing or clearing the screen
_binding_alt_A=(
    '"\eA":"'             #alt-A
    '\C-a\C-k'            #clear line
    '\\\n'                #bring us down onto a newline
    '\"$(_example.unpack \"${_examples[$_I]}\")\"' #pull the current example
    '\e\C-e"'             #interpolate
    )

# alt-e:
# clear screen and advance to next example
_binding_alt_e=(
    '"\ee":"'             #alt-e
    '\C-a\C-k'            #clear line
    '$(( _I < ${#_examples[@]} - 1 && _D && _I++,_D=1 ))' #increment,deinitialize
    '\e\C-e\C-a\C-k'      #interpolate to run above and clear the line
    '\\\n\C-l'            #bring us down onto a newline and clear screen
    '\"$(_example.unpack \"${_examples[$_I]}\")\"' #pull the current example
    '\e\C-e"'             #interpolate
    )

# alt-E:
# advance to next example without clearing the screen
_binding_alt_E=(
    '"\eE":"'             #alt-E
    '\C-a\C-k'            #clear line
    '  $(( _I < ${#_examples[@]} - 1 && _D && _I++,_D=1 ))' #increment,deinitialize
    '\e\C-e\C-a\C-k'      #interpolate to run above and clear the line
    '\\\n'                #bring us down onto a newline
    '\"$(_example.unpack \"${_examples[$_I]}\")\"' #pull the current example
    '\e\C-e"'             #interpolate
    )

# alt-s:
# side by side diff of previous and current example
_binding_alt_s=(
    '"\es":"'            #alt-s
    '\C-a\C-k'           #clear line
    '_example.ydiff'              #diff command
    '\C-l\n"'            #clear screen and execute function
    )

# alt-S:
# syntax highlighted side by side diff of previous and current example
_binding_alt_S=(
    '"\eS":"'            #alt-S
    '\C-a\C-k'           #clear line
    '_example.ydiff | hl --style clarity' #highlighted diff command
    '\C-l\n"'            #clear screen and execute function
    )

# alt-h:
# display current example with syntax highlighting
_binding_alt_h=(
    '"\eh":"' #alt-h
    '_example.highlight'
    '\C-m'
)

# alt-H:
# display USAGE text for ariketa
_binding_alt_H=(
    '"\eH":"' #alt-H
    '_ariketa.help'
    '\C-m'
)

# alt-P:
# Toggle between custom PS2 for giving example number and regular '>' prompt
_binding_alt_P=(
    '"\eP":"' #alt-P
    '_ps2.swap'
    '\C-m"'
    )

#load bindings
_bindings.load_from_arrays ${!_binding_*}