Skip to content

Instantly share code, notes, and snippets.

@ConnerWill
Created November 26, 2022 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConnerWill/afe110923effd9297f62abe024da4222 to your computer and use it in GitHub Desktop.
Save ConnerWill/afe110923effd9297f62abe024da4222 to your computer and use it in GitHub Desktop.
List all current ZSH keybindings
# shellcheck disable=2148,2296,2154
zsh-list-keybindings(){
typeset -A Zcolors
# Regular Colors
Zcolors[Color_Off]=''
Zcolors[Black]=''
Zcolors[Red]=''
Zcolors[Green]=''
Zcolors[Yellow]=''
Zcolors[Orange]=''
Zcolors[Blue]=''
Zcolors[Purple]=''
Zcolors[BGPurple]=''
Zcolors[Magenta]=''
Zcolors[Cyan]=''
Zcolors[White]=''
title="ZSH KEYBINDINGS"
# SLEEPTIME="${1:-0}"
SLEEPTIME=0
Xnumletters=${#${title}}
Xnumlet=$(( Xnumletters / 2 ))
Xcols=$(( COLUMNS / 2 ))
Xsubtr=$(( Xcols - Xnumlet ))
Xtcols="${(r:$Xsubtr:: :)}"
Xsolidline="${(r:$COLUMNS::▀:)}"
printf "${Zcolors[Cyan]}%s%s${Zcolors[BGPurple]}${Zcolors[Cyan]}%s${Zcolors[Color_Off]}%s\n${Zcolors[Cyan]}%s${Zcolors[Color_Off]}\n" "${Xsolidline}" "${Xtcols}" "${title}" "${Xtcols}" "${Xsolidline}"
print -f "${Zcolors[Magenta]}Current Keymap${Zcolors[Color_Off]}:\t${Zcolors[Blue]}%s${Zcolors[Color_Off]}\n" "${keym}"
print -f "${Zcolors[Magenta]}Keymaps${Zcolors[Color_Off]}:\t${Zcolors[Yellow]}%s${Zcolors[Color_Off]}\n" "${keymaps}"
for keym in "${keymaps[@]}"; do
numletters=${#${keym}}
numlet=$(( numletters / 2 ))
cols=$(( COLUMNS / 2 ))
subtr=$(( cols - numlet ))
tcols="${(r:$subtr:: :)}"
# solidline="${(r:$COLUMNS::—:)}"
solidline="${(r:$COLUMNS::━:)}"
bind=$(zsh -i --onecmd -c "bindkey -R -M ${keym} | sed -e 's/ /␟/' | column --separator='␟' --table")
[[ -n "${bind}" ]] && printf "${Zcolors[Yellow]}%s${Zcolors[Color_Off]}%s${Zcolors[Green]}%s${Zcolors[Color_Off]}%s${Zcolors[Yellow]}\n\b%s${Zcolors[Color_Off]}%s\n" "${solidline}" "${tcols}" "${keym}" "${tcols}" "${solidline}" "${bind}"
sleep $SLEEPTIME
done
unset title Xcols Xsubtr Xtcols Xnumlet Xnumletters Xsolidline
Xnumletters=${#${title}}
Xnumlet=$(( Xnumletters / 2 ))
Xcols=$(( COLUMNS / 2 ))
Xsubtr=$(( Xcols - Xnumlet ))
Xsolidline="${(r:$COLUMNS::▀:)}"
Xtcols="${(r:$Xsubtr:: :)}"
printf "${Zcolors[Cyan]}%s${Zcolors[Color_Off]}${Zcolors[Cyan]}%s${Zcolors[Color_Off]}\n" "${Xsolidline}" "${Xsolidline}"
}
####
## TODO: Add option to replace output key codes to more readable 'vim' key codes. (e.g. '^[C' → '<ESC>-C' or '<M-C>')
##
## $ printf '"^[C" forward-char\n"^Xm" _most_recent_file\n"^O" copybuffer' | sed -e 's/^\"\^\[/\"\<ESC\>\-/' -e 's/^\"\^/\"<C>-/'
####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment