show keybindings in command palette

This commit is contained in:
Dmytro Meleshko 2018-07-05 18:50:12 +03:00
parent bc4f313983
commit 3b08d735a4

View file

@ -1,20 +1,49 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
_command_palette_widgets=() typeset -A widgets_list
for widget_name widget_info in ${(kv)widgets}; do for widget_name widget_info in ${(kv)widgets}; do
[[ "$widget_name" == .* ]] && continue [[ "$widget_name" == .* ]] && continue
[[ "$widget_info" == completion:* ]] && continue [[ "$widget_info" == completion:* ]] && continue
_command_palette_widgets+=($widget_name) widgets_list[$widget_name]="none"
done done
for line in "${(@f)$(bindkey)}"; do
eval "line_parts=($line)"
widget_key="$line_parts[1]"
widget_name="$line_parts[2]"
widget_keys="$widgets_list[$widget_name]"
if [[ -z "$widget_keys" ]]; then
continue
else
case "$widget_keys" in
none) widget_keys="keys:" ;;
keys:*) widget_keys+=" " ;;
esac
widgets_list[$widget_name]="$widget_keys{$widget_key}"
fi
done
widgets_str=""
for widget_name widget_keys in ${(kv)widgets_list}; do
widgets_str+="$widget_name"
if [[ "$widget_keys" == keys:* ]]; then
widgets_str+=" ${widget_keys#keys:}"
fi
widgets_str+=$'\n'
done
widgets_str="${widgets_str%$'\n'}"
unset widget_{name,info,key,keys}
_command-palette() { _command-palette() {
local widget_name="$(echo "${(@j:\n:)_command_palette_widgets}" | peco)" local widget="$(echo "$widgets_str" | peco)"
if [[ -n "$widget_name" ]]; then if [[ -n "$widget" ]]; then
widget="${widget%%$' '*}"
python -c " python -c "
import fcntl, termios import fcntl, termios
with open('$TTY') as tty: with open('$TTY') as tty:
for char in '\x1bx$widget_name\n': for char in '\x1bx${widget}\n':
fcntl.ioctl(tty, termios.TIOCSTI, char) fcntl.ioctl(tty, termios.TIOCSTI, char)
" "
fi fi