From 5386101c3aac54256f08a94256f91ce109152124 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Thu, 13 Jul 2023 22:08:23 +0200 Subject: Add option --search-path Use this option to set a search path per command call. This option is only meant to be used with `fd` as FZF_DEFAULT_COMMAND. Example usage: vis:map(vis.modes.NORMAL, ' fh', ':fzf --search-path $HOME') vis:map(vis.modes.NORMAL, ' fr', ':fzf --search-path /') vis:map(vis.modes.NORMAL, ' fg', ':fzf --search-path "$(git rev-parse --show-toplevel)"') --- init.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 47386a5..39725cb 100644 --- a/init.lua +++ b/init.lua @@ -18,6 +18,15 @@ module.fzf_path = "fzf" module.fzf_args = "" vis:command_register("fzf", function(argv, force, win, selection, range) + local fzf_path = module.fzf_path + if argv[1] == "--search-path" then + table.remove(argv, 1) + local dir = table.remove(argv, 1) + fzf_path = ( + [[FZF_DEFAULT_COMMAND="$FZF_DEFAULT_COMMAND --search-path ]] .. dir .. [[" fzf]] + ) + end + local command = string.gsub([[ $fzf_path \ --header="Enter:edit,^s:split,^v:vsplit" \ @@ -25,7 +34,7 @@ vis:command_register("fzf", function(argv, force, win, selection, range) $fzf_args $args ]], '%$([%w_]+)', { - fzf_path=module.fzf_path, + fzf_path=fzf_path, fzf_args=module.fzf_args, args=table.concat(argv, " ") } -- cgit