#!/usr/bin/env bash
#
# x-xterm-update-keybindings
# Updates $HOME/.dotfiles/docs/tmux.md with my keybindings.

# shellcheck source=./../../scripts/shared.sh
source "$HOME/.dotfiles/scripts/shared.sh"

x-have tmux || {
  msg_err "tmux not found" && exit 0
}

TMUX_KEYBINDINGS_DOCS="$DOTFILES/docs/tmux-keybindings.md"

CB="\n\`\`\`\n"
KB=$(tmux lsk -Tprefix -N | sed -e 's/^/    /;')
H="# tmux keybindings\n"
L="\nLeader: \`<ctrl><space>\`\n"

# Generalize expanded $HOME to "$HOME"
KB="${KB//$HOME/\$HOME}"

msg "Outputting tmux keybindings to $TMUX_KEYBINDINGS_DOCS"
echo -e "${H}${L}${CB}${KB}${CB}" > "$TMUX_KEYBINDINGS_DOCS"
msg_done "Done!"
