From cd098e9538336d5313041f872b233cb31011239b Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Wed, 26 Jun 2019 10:32:20 +0200 Subject: [PATCH 1/2] Add configuration options for file and history searching commands Allows using alternative utilities like fd instead of find. Also allows changing which history entries to view and fixes regex used to remove history numbers. --- README.md | 9 +++++++++ autoload/widgets/fzf-change-directory | 2 +- autoload/widgets/fzf-edit-files | 8 ++++---- autoload/widgets/fzf-insert-directory | 12 +++++++----- autoload/widgets/fzf-insert-files | 8 ++++---- autoload/widgets/fzf-insert-history | 4 ++-- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a34f51c..0fac75f 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,15 @@ if zplug check 'ytet5uy4/fzf-widgets'; then # Start fzf in a tmux pane FZF_WIDGET_TMUX=1 + + # use fd for finding directories and files + FZF_CHANGE_DIR_COMMAND="fd -t d" + FZF_INSERT_DIR_COMMAND="fd -t d" + FZF_INSERT_FILES_COMMAND="fd -t f" + FZF_EDIT_FILES_COMMAND="fd -t f" + + # modify history command to remove duplicates + FZF_HISTORY_COMMAND="fc -l 1 | sed 's/^ *[0-9]*\*? //g' | awk '!seen[\$0]++'" fi ``` diff --git a/autoload/widgets/fzf-change-directory b/autoload/widgets/fzf-change-directory index d58bf7d..1dbf088 100644 --- a/autoload/widgets/fzf-change-directory +++ b/autoload/widgets/fzf-change-directory @@ -2,7 +2,7 @@ __fzf::widget::init 'cd --' || return 1 -find . -mindepth 1 -type d -o -type l 2>/dev/null | \ +eval "${FZF_CHANGE_DIR_FIND_COMMAND:-"find . -mindepth 1 -type d -o -type l 2>/dev/null"}" | \ sed 's|\./||g' | \ __fzf::widget::select $FZF_WIDGET_OPTS[change-dir] +m | \ __fzf::widget::insert -q diff --git a/autoload/widgets/fzf-edit-files b/autoload/widgets/fzf-edit-files index 75a4807..5748a6e 100644 --- a/autoload/widgets/fzf-edit-files +++ b/autoload/widgets/fzf-edit-files @@ -2,10 +2,10 @@ __fzf::widget::init "$EDITOR --" || return 1 -find -L . -type f -print -o -type l -print -o \ - \( -path '*/\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune \ - 2> /dev/null | \ - sed 's|\./||g' | \ +eval "${FZF_EDIT_FILES_COMMAND:-"find -L . -type f -print -o -type l -print -o \\ + \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \\ + 2> /dev/null | \\ + sed 's|\\./||g'"}" | \ __fzf::widget::select $FZF_WIDGET_OPTS[edit-files] -m | \ __fzf::widget::insert -q diff --git a/autoload/widgets/fzf-insert-directory b/autoload/widgets/fzf-insert-directory index 8e9c76c..ef8d827 100644 --- a/autoload/widgets/fzf-insert-directory +++ b/autoload/widgets/fzf-insert-directory @@ -2,10 +2,12 @@ __fzf::widget::init || return 1 -find -L . -type d -print -o -type l -print -o \ - \( -path '*/\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune \ - 2> /dev/null | \ - grep -v '^.$' | \ - sed 's|\./||g' | \ +eval "${FZF_INSERT_DIR_FIND_COMMAND:-"find -L . \\ + -type d -print -o -type l -print -o \\ + \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) \\ + -prune 2> /dev/null | \\ + grep -v '^.$' | \\ + sed 's|\\./||g' +"}" | \ __fzf::widget::select $FZF_WIDGET_OPTS[insert-directory] +m | \ __fzf::widget::insert -q diff --git a/autoload/widgets/fzf-insert-files b/autoload/widgets/fzf-insert-files index 2bb84b9..093d2f2 100644 --- a/autoload/widgets/fzf-insert-files +++ b/autoload/widgets/fzf-insert-files @@ -2,9 +2,9 @@ __fzf::widget::init || return 1 -find -L . -type f -print -o -type l -print -o \ - \( -path '*/\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune \ - 2> /dev/null | \ - sed 's|\./||g' | \ +eval "${FZF_INSERT_FILE_COMMAND:-"find -L . -type f -print -o -type l -print -o \\ + \\( -path '*/\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \\ + 2> /dev/null | \\ + sed 's|\./||g'"}" | \ __fzf::widget::select $FZF_WIDGET_OPTS[insert-files] -m | \ __fzf::widget::insert -q diff --git a/autoload/widgets/fzf-insert-history b/autoload/widgets/fzf-insert-history index 9bff854..83536c6 100644 --- a/autoload/widgets/fzf-insert-history +++ b/autoload/widgets/fzf-insert-history @@ -2,8 +2,8 @@ __fzf::widget::init || return 1 -fc -l 1 | \ +eval "${FZF_HISTORY_COMMAND:-"fc -l 1"}" | \ __fzf::widget::select --tac --tiebreak=index \ --bind=ctrl-r:toggle-sort $FZF_WIDGET_OPTS[insert-history] --query="$LBUFFER" +m | \ - sed 's/ *[0-9]* //g' | \ + sed 's/^ *[0-9]*\*? //g' | \ __fzf::widget::replace From 100941f6f6481a518dcc7fd07edd2a9093460f6c Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Wed, 7 Aug 2019 11:18:32 +0200 Subject: [PATCH 2/2] Fix variable names in README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0fac75f..3b5b112 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,9 @@ if zplug check 'ytet5uy4/fzf-widgets'; then FZF_WIDGET_TMUX=1 # use fd for finding directories and files - FZF_CHANGE_DIR_COMMAND="fd -t d" - FZF_INSERT_DIR_COMMAND="fd -t d" - FZF_INSERT_FILES_COMMAND="fd -t f" + FZF_CHANGE_DIR_FIND_COMMAND="fd -t d" + FZF_INSERT_DIR_FIND_COMMAND="fd -t d" + FZF_INSERT_FILE_COMMAND="fd -t f" FZF_EDIT_FILES_COMMAND="fd -t f" # modify history command to remove duplicates