From b31e62a4db4d23d55e8d67adcc02919a7b011df4 Mon Sep 17 00:00:00 2001 From: p1r473 Date: Sun, 12 May 2024 11:55:29 -0400 Subject: [PATCH] fzf buffer fix for browse (#122) * Update wd.sh * Update wd.plugin.zsh * Update README.md --- README.md | 2 +- wd.plugin.zsh | 9 +++++---- wd.sh | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0c71c05..254d405 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ rm -f ~/.zcompdump; compinit If you want to make use of the `fzf`-powered browse feature to fuzzy search through all your warp points, set up a keybind in your `.zshrc`: ```zsh -bindkey '^G' wd_browse +bindkey ${FZF_WD_BINDKEY:-'^B'} fuzzy_wd_widget ``` ## Usage diff --git a/wd.plugin.zsh b/wd.plugin.zsh index 9e0c7ff..9910cb9 100644 --- a/wd.plugin.zsh +++ b/wd.plugin.zsh @@ -14,7 +14,8 @@ eval "wd() { source '${0:A:h}/wd.sh' }" wd > /dev/null -# Register the function as a Zsh widget -zle -N wd_browse -# Bind the widget to a key combination -bindkey '^G' wd_browse +zle -N wd_browse_widget +zle -N wd_restore_buffer +autoload -Uz add-zle-hook-widget +add-zle-hook-widget line-init wd_restore_buffer +bindkey ${FZF_WD_BINDKEY:-'^B'} wd_browse_widget diff --git a/wd.sh b/wd.sh index c4f422c..fd7eb88 100755 --- a/wd.sh +++ b/wd.sh @@ -243,6 +243,23 @@ wd_browse() { fi } +wd_browse_widget() { + if [[ -e $WD_CONFIG ]]; then + wd_browse + saved_buffer=$BUFFER + saved_cursor=$CURSOR + BUFFER= + zle redisplay + zle accept-line + fi +} + +wd_restore_buffer() { + BUFFER=$saved_buffer + CURSOR=$saved_cursor + saved_buffer= + saved_cursor=1 +} wd_list_all() { wd_print_msg "$WD_BLUE" "All warp points:" @@ -371,7 +388,7 @@ wd_export_static_named_directories() { fi } -local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc} +WD_CONFIG=${WD_CONFIG:-$HOME/.warprc} local WD_QUIET=0 local WD_EXIT_CODE=0 local WD_DEBUG=0