From fc121e7fd0544f477ca7e997c33d6faa2e96b367 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 20 Jun 2020 00:12:39 +0200 Subject: [PATCH] [zsh] Expand fzf-tab functionality Will now contain additional functionality for ps, kill, and cd (preview etc). Will also color things which have LS_COLORS set (done automatically through lscolors-git file). --- bootstrap/packages.txt | 1 + zsh/.config/zsh/.zshrc | 46 +++++++++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/bootstrap/packages.txt b/bootstrap/packages.txt index f3fbca2..e5e5a88 100644 --- a/bootstrap/packages.txt +++ b/bootstrap/packages.txt @@ -51,6 +51,7 @@ linux-lts linux-lts-headers littler logrotate +lscolors-git lvm2 lynx man-db diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc index 6da9b9d..80f2559 100644 --- a/zsh/.config/zsh/.zshrc +++ b/zsh/.config/zsh/.zshrc @@ -14,7 +14,6 @@ fi # Set completion style # The following lines were added by compinstall zstyle ':completion:*' completer _complete _ignored _approximate -zstyle ':completion:*' list-colors '' zstyle ':completion:*' matcher-list '' '+m:{[:lower:]}={[:upper:]} r:|[._-]=** r:|=**' zstyle ':completion:*' menu select=1 zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s @@ -22,14 +21,49 @@ zstyle :compinstall filename "$ZSHCONFDIR/.zshrc" # End of lines added by compinstall # load plugins +PLUG_FOLDER="/usr/share/zsh/plugins" source /usr/share/zsh-theme-powerlevel10k/powerlevel10k.zsh-theme -source /usr/share/zsh/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh -source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh -source /usr/share/zsh/plugins/alias-tips/alias-tips.plugin.zsh -source /usr/share/zsh/plugins/fzf-tab/fzf-tab.plugin.zsh source /usr/share/oh-my-zsh/plugins/colored-man-pages/colored-man-pages.plugin.zsh source /usr/share/oh-my-zsh/plugins/command-not-found/command-not-found.plugin.zsh source /usr/share/nvm/init-nvm.sh +[ -e $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh ] && source $PLUG_FOLDER/fzf-tab/fzf-tab.plugin.zsh +# these need to be sourced after fzf-tab +[ -e $PLUG_FOLDER/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh ] && source $PLUG_FOLDER/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh +[ -e $PLUG_FOLDER/alias-tips/alias-tips.plugin.zsh ] && source $PLUG_FOLDER/alias-tips/alias-tips.plugin.zsh +[ -e $PLUG_FOLDER/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh ] && source $PLUG_FOLDER/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh +unset PLUG_FOLDER + +# simple fzf-tab settings +FZF_TAB_COMMAND=( + fzf + --ansi # Enable ANSI color support, necessary for showing groups + --expect='$continuous_trigger' # For continuous completion + '--color=hl:$(( $#headers == 0 ? 108 : 255 ))' + --nth=2,3 --delimiter='\x00' # Don't search prefix + --layout=reverse --height='${FZF_TMUX_HEIGHT:=75%}' + --tiebreak=begin -m --bind=tab:down,btab:up,change:top,ctrl-space:toggle --cycle + '--query=$query' # $query will be expanded to query string at runtime. + '--header-lines=$#headers' # $#headers will be expanded to lines of headers at runtime +) +zstyle ':fzf-tab:*' command $FZF_TAB_COMMAND +# default color +[ -e /usr/share/LS_COLORS/dircolors.sh ] && source /usr/share/LS_COLORS/dircolors.sh +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +# some boilerplate code to define the variable `extract` which will be used later +local extract=" +# trim input(what you select) +local in=\${\${\"\$(<{f})\"%\$'\0'*}#*\$'\0'} +# get ctxt for current completion(some thing before or after the current word) +local -A ctxt=(\"\${(@ps:\2:)CTXT}\") +# real path +local realpath=\${ctxt[IPREFIX]}\${ctxt[hpre]}\$in +realpath=\${(Qe)~realpath} +" +# give a preview of commandline arguments when completing `kill` +zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm,cmd -w -w" +zstyle ':fzf-tab:complete:kill:argument-rest' extra-opts --preview=$extract'ps --pid=$in[(w)1] -o cmd --no-headers -w -w' --preview-window=down:3:wrap +# give a preview of directory by exa when completing cd +zstyle ':fzf-tab:complete:cd:*' extra-opts --preview=$extract'exa -1 --color=always $realpath' # load completion, extended zsh moving syntax, zle edit in vim (or other $EDITOR) possibility autoload -Uz compinit zmv edit-command-line @@ -62,8 +96,6 @@ ENABLE_CORRECTION="true" zstyle ':completion:*' accept-exact '*(N)' zstyle ':completion:*' use-cache on zstyle ':completion:*' cache-path "${XDG_CACHE_HOME:-$HOME/.cache}/zshcompcache" -# shellcheck disable=SC2016 -zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)*==34=34}:${(s.:.)LS_COLORS}")' ### history ## Set ZSH History defaults