From 4b9337b4a9964b21de775ce636a4c5874b54076b Mon Sep 17 00:00:00 2001 From: chenyc Date: Tue, 3 Jan 2023 11:56:36 +0800 Subject: [PATCH] update fzf-tab --- lib/file_preview.sh | 2 +- plugins/fzf-tab/fzf-tab.zsh | 20 ++++++++++++-------- plugins/fzf-tab/lib/-ftb-fzf | 2 +- plugins/fzf-tab/lib/ftb-tmux-popup | 3 +++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/file_preview.sh b/lib/file_preview.sh index d63ee2a..03e0424 100755 --- a/lib/file_preview.sh +++ b/lib/file_preview.sh @@ -4,7 +4,7 @@ category=${mime%%/*} if [ -d "$1" ]; then exa -l --no-user --no-time --icons "$1" 2>/dev/null || ls --color=always "$1" 2>/dev/null || ls -G "$1" elif [ "$category" = text ]; then - (bat -p --color=always "$1" || cat "$1") 2>/dev/null | head -100 + (bat -p --color=always "$1" || cat "$1") 2>/dev/null | head -1000 elif [ "$category" = image ]; then command -v ueberzug 2&>/dev/null && bash $OMZ/lib/img_preview.sh "$1"|| img2txt "$1" else diff --git a/plugins/fzf-tab/fzf-tab.zsh b/plugins/fzf-tab/fzf-tab.zsh index a3fb396..3269670 100644 --- a/plugins/fzf-tab/fzf-tab.zsh +++ b/plugins/fzf-tab/fzf-tab.zsh @@ -8,10 +8,10 @@ # thanks Valodim/zsh-capture-completion -ftb-compadd() { # parse all options - local -A apre hpre dscrs _oad + local -A apre hpre dscrs _oad _mesg local -a isfile _opts __ expl zparseopts -E -a _opts P:=apre p:=hpre d:=dscrs X+:=expl O:=_oad A:=_oad D:=_oad f=isfile \ - i: S: s: I: x: r: R: W: F: M+: E: q e Q n U C \ + i: S: s: I: x:=_mesg r: R: W: F: M+: E: q e Q n U C \ J:=__ V:=__ a=__ l=__ k=__ o=__ 1=__ 2=__ # store $curcontext for further usage @@ -34,6 +34,9 @@ builtin compadd -A __hits -D __dscr "$@" local ret=$? if (( $#__hits == 0 )); then + if is-at-least 5.9 && (( $#_mesg != 0 )); then + builtin compadd -x $mesg + fi return $ret fi @@ -208,7 +211,6 @@ fzf-tab-debug() { } fzf-tab-complete() { - bash $OMZ/lib/get_cursor.sh # this name must be ugly to avoid clashes local -i _ftb_continue=1 _ftb_continue_last=0 _ftb_accept=0 ret=0 # hide the cursor until finishing completion, so that users won't see cursor up and down @@ -337,16 +339,16 @@ toggle-fzf-tab() { } build-fzf-tab-module() { - local MACOS + local use_bundle local NPROC if [[ ${OSTYPE} == darwin* ]]; then - MACOS=true + [[ -n ${module_path[1]}/**/*.bundle(#qN) ]] && use_bundle=true NPROC=$(sysctl -n hw.logicalcpu) else NPROC=$(nproc) fi pushd $FZF_TAB_HOME/modules - CPPFLAGS=-I/usr/local/include CFLAGS="-g -Wall -O2" LDFLAGS=-L/usr/local/lib ./configure --disable-gdbm --without-tcsetpgrp ${MACOS:+DL_EXT=bundle} + CPPFLAGS=-I/usr/local/include CFLAGS="-g -Wall -O2" LDFLAGS=-L/usr/local/lib ./configure --disable-gdbm --without-tcsetpgrp ${use_bundle:+DL_EXT=bundle} make -j${NPROC} local ret=$? popd @@ -377,9 +379,11 @@ typeset -ga _ftb_group_colors=( () { emulate -L zsh -o extended_glob - fpath+=($FZF_TAB_HOME/lib) + if (( ! $fpath[(I)$FZF_TAB_HOME/lib] )); then + fpath+=($FZF_TAB_HOME/lib) + fi - autoload -Uz -- $FZF_TAB_HOME/lib/-#ftb*(:t) + autoload -Uz is-at-least -- $FZF_TAB_HOME/lib/-#ftb*(:t) if (( $+FZF_TAB_COMMAND || $+FZF_TAB_OPTS || $+FZF_TAB_QUERY || $+FZF_TAB_SINGLE_GROUP || $+fzf_tab_preview_init )) \ || zstyle -m ":fzf-tab:*" command '*' \ diff --git a/plugins/fzf-tab/lib/-ftb-fzf b/plugins/fzf-tab/lib/-ftb-fzf index aa1d770..49cd277 100755 --- a/plugins/fzf-tab/lib/-ftb-fzf +++ b/plugins/fzf-tab/lib/-ftb-fzf @@ -80,7 +80,7 @@ fi _ftb_query="${_ftb_query}$(command "$dd" bs=1G count=1 status=none iflag=nonblock < /dev/tty 2>/dev/null)" || true -$fzf_command \ +SHELL=$ZSH_NAME $fzf_command \ --ansi \ --bind=$binds \ --bind="${switch_group[1]}:reload($reload_command -1),${switch_group[2]}:reload($reload_command 1)" \ diff --git a/plugins/fzf-tab/lib/ftb-tmux-popup b/plugins/fzf-tab/lib/ftb-tmux-popup index 7a46d27..6314241 100755 --- a/plugins/fzf-tab/lib/ftb-tmux-popup +++ b/plugins/fzf-tab/lib/ftb-tmux-popup @@ -70,6 +70,9 @@ if (( cursor_y * 2 > window_height )); then # show above the cursor popup_height=$(( min(max(comp_lines + 4, popup_min_size[2]), cursor_y - window_top) + adjust_height )) popup_y=$cursor_y + if zstyle -T ":fzf-tab:$_ftb_curcontext" popup-smart-tab; then + fzf_opts+=(--bind=tab:up,btab:down) + fi else # show below the cursor popup_height=$(( min(max(comp_lines + 4, popup_min_size[2]), window_height - cursor_y + window_top - 1) + adjust_height ))