From d108d6e399aa98f828a8996cb2d822a141260b4c Mon Sep 17 00:00:00 2001 From: Bojin Li Date: Thu, 26 Mar 2026 13:58:53 +1100 Subject: [PATCH] fix: add safe configurable fzf overrides --- README.md | 13 +++++++++++++ conf.d/fifc.fish | 3 +++ functions/_fifc.fish | 17 +++++++++++------ functions/_fifc_action.fish | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index b565ca0..d3cf11f 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,19 @@ By default fifc override `tab`, but you can assign another keybinding: set -U fifc_keybinding \cx ``` +fifc will also by default use `rm` to remove temporary files, this can changed: + +```fish +# Use trash instead of rm +set -U fifc_rm_cmd trash +``` + +To append custom fzf options globally, for example to disable the `--exact` flag and increase the fuzziness: + +```fish +set -U fifc_custom_fzf_opts +e +``` + fifc can use modern tools if available: | Prefer | Fallback to | Used for | Custom options | diff --git a/conf.d/fifc.fish b/conf.d/fifc.fish index 0268c60..423575a 100644 --- a/conf.d/fifc.fish +++ b/conf.d/fifc.fish @@ -11,6 +11,9 @@ if status is-interactive set -qU fifc_open_keybinding or set -U fifc_open_keybinding ctrl-o + set -qU fifc_rm_cmd + or set -U fifc_rm_cmd rm + for mode in default insert bind --mode $mode \t _fifc bind --mode $mode $fifc_keybinding _fifc diff --git a/functions/_fifc.fish b/functions/_fifc.fish index b5def25..a1128f5 100644 --- a/functions/_fifc.fish +++ b/functions/_fifc.fish @@ -3,11 +3,11 @@ function _fifc set -l result set -Ux _fifc_extract_regex set -gx _fifc_complist_path (string join '' (mktemp) "_fifc") - set -gx _fifc_custom_fzf_opts set -gx fifc_extracted set -gx fifc_commandline set -gx fifc_token (commandline --current-token) set -gx fifc_query "$fifc_token" + set -gx fifc_effective_fzf_opts $fifc_custom_fzf_opts # Get commandline buffer if test "$argv" = "" @@ -25,7 +25,7 @@ function _fifc set -gx fifc_group (_fifc_completion_group) set source_cmd (_fifc_action source) - set fifc_fzf_query (string trim --chars '\'' -- "$fifc_fzf_query") + set fifc_safe_query (string unescape -- "$fifc_query") set -l fzf_cmd " _fifc_launched_by_fzf=1 SHELL=fish fzf \ @@ -41,8 +41,8 @@ function _fifc --header '$header' \ --preview '_fifc_action preview {} {q}' \ --bind='$fifc_open_keybinding:execute(_fifc_action open {} {q} &> /dev/tty)' \ - --query '$fifc_query' \ - $_fifc_custom_fzf_opts" + --query '$fifc_safe_query' \ + $fifc_effective_fzf_opts" set -l cmd (string join -- " | " $source_cmd $fzf_cmd) # We use eval hack because wrapping source command @@ -79,11 +79,16 @@ function _fifc commandline --function repaint - rm $_fifc_complist_path + set -l fifc_rm_cmd_effective rm + if set -q fifc_rm_cmd + set fifc_rm_cmd_effective $fifc_rm_cmd + end + + command $fifc_rm_cmd_effective $_fifc_complist_path # Clean state set -e _fifc_extract_regex - set -e _fifc_custom_fzf_opts set -e _fifc_complist_path + set -e fifc_effective_fzf_opts set -e fifc_token set -e fifc_group set -e fifc_extracted diff --git a/functions/_fifc_action.fish b/functions/_fifc_action.fish index 282736b..a87d0b8 100644 --- a/functions/_fifc_action.fish +++ b/functions/_fifc_action.fish @@ -53,7 +53,7 @@ function _fifc_action eval $$comp[$i][4] break else if test "$action" = source; and test -n "$$comp[$i][5]" - set _fifc_custom_fzf_opts "$$comp[$i][6]" + set fifc_effective_fzf_opts $fifc_custom_fzf_opts $$comp[$i][6] if functions "$$comp[$i][5]" 1>/dev/null eval $$comp[$i][5] else