mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
show keybindings in command palette
This commit is contained in:
parent
bc4f313983
commit
3b08d735a4
1 changed files with 35 additions and 6 deletions
|
@ -1,20 +1,49 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
_command_palette_widgets=()
|
||||
|
||||
typeset -A widgets_list
|
||||
for widget_name widget_info in ${(kv)widgets}; do
|
||||
[[ "$widget_name" == .* ]] && continue
|
||||
[[ "$widget_info" == completion:* ]] && continue
|
||||
_command_palette_widgets+=($widget_name)
|
||||
widgets_list[$widget_name]="none"
|
||||
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() {
|
||||
local widget_name="$(echo "${(@j:\n:)_command_palette_widgets}" | peco)"
|
||||
if [[ -n "$widget_name" ]]; then
|
||||
local widget="$(echo "$widgets_str" | peco)"
|
||||
if [[ -n "$widget" ]]; then
|
||||
widget="${widget%%$' '*}"
|
||||
python -c "
|
||||
import fcntl, termios
|
||||
with open('$TTY') as tty:
|
||||
for char in '\x1bx$widget_name\n':
|
||||
for char in '\x1bx${widget}\n':
|
||||
fcntl.ioctl(tty, termios.TIOCSTI, char)
|
||||
"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue