From c10ba15ff2f6c0eac45ae0c929fe318e251b5062 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Wed, 4 Jul 2018 23:56:09 +0300 Subject: [PATCH] add basic command palette widget --- oh-my-zsh.zsh | 2 +- widgets.zsh | 23 +++++++++++++++++++++++ zshrc | 5 +++-- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 widgets.zsh diff --git a/oh-my-zsh.zsh b/oh-my-zsh.zsh index 9d64e9f..9579567 100644 --- a/oh-my-zsh.zsh +++ b/oh-my-zsh.zsh @@ -35,7 +35,7 @@ configure_oh_my_zsh() { git common-aliases extract - zsh-syntax-highlighting + # zsh-syntax-highlighting ) if is_linux; then diff --git a/widgets.zsh b/widgets.zsh new file mode 100644 index 0000000..62f875a --- /dev/null +++ b/widgets.zsh @@ -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 diff --git a/zshrc b/zshrc index 790c80a..d31b59b 100755 --- a/zshrc +++ b/zshrc @@ -14,10 +14,11 @@ find_dotfiles_dir() { find_dotfiles_dir -for script in "$DOTFILES_DIR"/{functions,path,exports,aliases,oh-my-zsh}.zsh; do - source "$script" +for script in functions path exports aliases oh-my-zsh widgets; do + source "${DOTFILES_DIR}/${script}.zsh" done +source_if_exists "$ZSH/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh" run_before rbenv 'eval "$(rbenv init -)"' 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"'