add basic command palette widget

This commit is contained in:
Dmytro Meleshko 2018-07-04 23:56:09 +03:00
parent 27d0185cf1
commit c10ba15ff2
3 changed files with 27 additions and 3 deletions

View file

@ -35,7 +35,7 @@ configure_oh_my_zsh() {
git git
common-aliases common-aliases
extract extract
zsh-syntax-highlighting # zsh-syntax-highlighting
) )
if is_linux; then if is_linux; then

23
widgets.zsh Normal file
View file

@ -0,0 +1,23 @@
#!/usr/bin/env zsh
_command_palette_widgets=()
for widget_name widget_info in ${(kv)widgets}; do
[[ "$widget_name" == .* ]] && continue
[[ "$widget_info" == completion:* ]] && continue
_command_palette_widgets+=($widget_name)
done
_command-palette() {
local widget_name="$(echo "${(@j:\n:)_command_palette_widgets}" | peco)"
if [[ -n "$widget_name" ]]; then
python -c "
import fcntl, termios
with open('$TTY') as tty:
for char in '\x1bx$widget_name\n':
fcntl.ioctl(tty, termios.TIOCSTI, char)
"
fi
}
zle -N command-palette _command-palette
bindkey "^[P" command-palette

5
zshrc
View file

@ -14,10 +14,11 @@ find_dotfiles_dir() {
find_dotfiles_dir find_dotfiles_dir
for script in "$DOTFILES_DIR"/{functions,path,exports,aliases,oh-my-zsh}.zsh; do for script in functions path exports aliases oh-my-zsh widgets; do
source "$script" source "${DOTFILES_DIR}/${script}.zsh"
done done
source_if_exists "$ZSH/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh"
run_before rbenv 'eval "$(rbenv init -)"' run_before rbenv 'eval "$(rbenv init -)"'
run_before sdk 'source_if_exists "$SDKMAN_DIR/bin/sdkman-init.sh"' run_before sdk 'source_if_exists "$SDKMAN_DIR/bin/sdkman-init.sh"'
run_before yarn 'source_if_exists "$(yarn global dir)/node_modules/tabtab/.completions/yarn.zsh"' run_before yarn 'source_if_exists "$(yarn global dir)/node_modules/tabtab/.completions/yarn.zsh"'