#!/usr/bin/env bash

# Show a list of available key bindings

dlbinds() {
    curl -s 'https://raw.githubusercontent.com/instantOS/instantos.github.io/main/youtube/hotkeys.md' 2>/dev/null |
        sed 's/^\([^|#]\)/    \1/g' |
        sed 's/^##*[ ]*/ /g' >~/.cache/instantos/hotkeys.md \
    || \
    cp /usr/share/instantutils/keybinds .cache/instantos/hotkeys.md
}

if ! [ -e ~/.cache/instantos/hotkeys.md ]; then
    mkdir -p ~/.cache/instantos 2>&1 /dev/null
    dlbinds
fi

cat ~/.cache/instantos/hotkeys.md >/tmp/hotkeys

# allow user to add to the list
if [ -e ~/.config/instantos/hotkeys ]; then
    echo -e "user generated notes:\n" >>/tmp/hotkeys
    cat ~/.config/instantos/hotkeys >>/tmp/hotkeys
fi

dlbinds &

# optional GUI mode
if [ -z "$1" ]; then
    less --mouse --wheel-lines=3 /tmp/hotkeys
else
    sed 's/^/>/g' /tmp/hotkeys | 
      instantmenu -i -c -l 35 -M -bw 3
fi
