From a6f7caf20d01db16bbf36ba39308d7ca8c616e20 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 10 Nov 2013 18:13:04 +0100 Subject: [PATCH 1/2] new zsh widgets + new fzf-cd-widget for running cd * fzf-file-widget now properly escapes the special characters and supports multi-selection * fzf-history-widget replaces the current line instead of appending to it --- README.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index efd6c80..8b8f69e 100644 --- a/README.md +++ b/README.md @@ -177,20 +177,35 @@ zsh widgets ----------- ```sh -# CTRL-T - Paste the selected file path into the command line +# CTRL-T - Paste the selected file(s) path into the command line fzf-file-widget() { - LBUFFER+=$( - find * -path '*/\.*' -prune \ - -o -type f -print \ - -o -type l -print 2> /dev/null | fzf) + local FILES + local IFS=" +" + FILES=($( + find * -path '*/\.*' -prune \ + -o -type f -print \ + -o -type l -print 2> /dev/null | fzf -m)) + unset IFS + FILES=$FILES:q + LBUFFER="${LBUFFER%% #} $FILES" zle redisplay } zle -N fzf-file-widget bindkey '^T' fzf-file-widget +# ALT-C - cd into the selected directory +fzf-cd-widget() { + cd ${$(find * -path '*/\.*' -prune \ + -o -type d -print 2> /dev/null | fzf):-.} + zle reset-prompt +} +zle -N fzf-cd-widget +bindkey '\ec' fzf-cd-widget + # CTRL-R - Paste the selected command from history into the command line fzf-history-widget() { - LBUFFER+=$(history | fzf +s | sed "s/ *[0-9]* *//") + LBUFFER=$(history | fzf +s | sed "s/ *[0-9]* *//") zle redisplay } zle -N fzf-history-widget From b2ac52462ccb678d0d5ae1a3d6dd4dab129377de Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 10 Nov 2013 18:57:47 +0100 Subject: [PATCH 2/2] zsh widget fix * fzf-cd-widget properly escapes the special characters --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b8f69e..f14ec94 100644 --- a/README.md +++ b/README.md @@ -196,8 +196,8 @@ bindkey '^T' fzf-file-widget # ALT-C - cd into the selected directory fzf-cd-widget() { - cd ${$(find * -path '*/\.*' -prune \ - -o -type d -print 2> /dev/null | fzf):-.} + cd "${$(find * -path '*/\.*' -prune \ + -o -type d -print 2> /dev/null | fzf):-.}" zle reset-prompt } zle -N fzf-cd-widget