1provide-module sane-scroll %~
2 define-command -docstring %{
3 sane-scroll [<switches>] <up|down>: Scroll cursor up/down. Supports <count>.
4 Switches:
5 -center Center screen after cursor move.
6 -win Scroll by half-window height.
7 } -params 1..3 sane-scroll %{
8 execute-keys %sh{
9 while [ "$#" -gt 0 ]; do
10 case "$1" in
11 -center)
12 center=true
13 shift
14 ;;
15 -win)
16 win=true
17 shift
18 ;;
19 -*)
20 echo ":fail Unknown switch $1<ret>"
21 exit 1
22 ;;
23 *)
24 break
25 ;;
26 esac
27 done
28
29 if [ "$win" = true ]; then
30 count=$((kak_window_height / 2))
31 else
32 count="$kak_count"
33 fi
34 case $1 in
35 up)
36 dir="k"
37 ;;
38 down)
39 dir="j"
40 ;;
41 *)
42 echo ":fail Invalid scroll direction<ret>"
43 ;;
44 esac
45 echo "${count}${dir}"
46 if [ "$center" = true ]; then
47 echo "vv"
48 else
49 echo "${count}v${dir}"
50 fi
51 }
52 }
53~