From 6ad705401fe0fe20fa4228f5aeb8821e2094e8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olle=20Hyn=C3=A9n=20Ulfsj=C3=B6=C3=B6?= Date: Tue, 15 Oct 2024 11:04:43 +0200 Subject: [PATCH] Allow override of rm and custom fzf options --- README.md | 7 +++++++ conf.d/fifc.fish | 8 ++++++++ functions/_fifc.fish | 7 +++---- functions/_fifc_action.fish | 2 +- tests/test_exposed_vars.fish | 2 +- tests/test_group.fish | 2 +- tests/test_match_order.fish | 2 +- tests/test_source.fish | 2 +- 8 files changed, 23 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b565ca0..41f1451 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,13 @@ 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 +``` + 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 9feac9c..d724bd1 100644 --- a/conf.d/fifc.fish +++ b/conf.d/fifc.fish @@ -11,6 +11,14 @@ if not set --query --universal fifc_open_keybinding set --universal fifc_open_keybinding ctrl-o end +if not set --query --universal fifc_rm_cmd + set --universal fifc_rm_cmd rm +end + +if not set --query --universal fifc_custom_fzf_opts + set --universal fifc_custom_fzf_opts +end + # Private set -gx _fifc_comp_count 0 diff --git a/functions/_fifc.fish b/functions/_fifc.fish index f40d25e..4da9e53 100644 --- a/functions/_fifc.fish +++ b/functions/_fifc.fish @@ -3,7 +3,6 @@ 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) @@ -42,7 +41,8 @@ function _fifc --preview '_fifc_action preview {} {q}' \ --bind='$fifc_open_keybinding:execute(_fifc_action open {} {q} &> /dev/tty)' \ --query '$fifc_query' \ - $_fifc_custom_fzf_opts" + $fifc_custom_fzf_opts" + echo $fzf_cmd set -l cmd (string join -- " | " $source_cmd $fzf_cmd) # We use eval hack because wrapping source command @@ -79,10 +79,9 @@ function _fifc commandline --function repaint - rm $_fifc_complist_path + $fifc_rm_cmd $_fifc_complist_path # Clean state set -e _fifc_extract_regex - set -e _fifc_custom_fzf_opts set -e _fifc_complist_path set -e fifc_token set -e fifc_group diff --git a/functions/_fifc_action.fish b/functions/_fifc_action.fish index 282736b..b957435 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_custom_fzf_opts "$$comp[$i][6]" if functions "$$comp[$i][5]" 1>/dev/null eval $$comp[$i][5] else diff --git a/tests/test_exposed_vars.fish b/tests/test_exposed_vars.fish index a1aeea1..7111c10 100644 --- a/tests/test_exposed_vars.fish +++ b/tests/test_exposed_vars.fish @@ -40,4 +40,4 @@ set -x fifc_query set actual (_fifc_action "preview" "$dir/file 1.txt" "1") @test "exposed vars fifc_query" "$actual" = 1 -rm $_fifc_complist_path +$fifc_rm_cmd $_fifc_complist_path diff --git a/tests/test_group.fish b/tests/test_group.fish index 5af3b83..afe64ab 100644 --- a/tests/test_group.fish +++ b/tests/test_group.fish @@ -20,4 +20,4 @@ set actual (_fifc_completion_group) set -e _fifc_complist set -e fifc_commandline -rm $_fifc_complist_path +$fifc_rm_cmd $_fifc_complist_path diff --git a/tests/test_match_order.fish b/tests/test_match_order.fish index 77c930b..92210dd 100644 --- a/tests/test_match_order.fish +++ b/tests/test_match_order.fish @@ -55,4 +55,4 @@ set actual (_fifc_action "preview" "$dir/file 1.txt") set -e fifc_commandline set -gx _fifc_unordered_comp $curr_fifc_unordered_comp set -gx _fifc_ordered_comp $curr_fifc_ordered_comp -rm $_fifc_complist_path +$fifc_rm_cmd $_fifc_complist_path diff --git a/tests/test_source.fish b/tests/test_source.fish index 8ee8300..719264d 100644 --- a/tests/test_source.fish +++ b/tests/test_source.fish @@ -24,4 +24,4 @@ set actual (_fifc_action "source") set -e fifc_commandline set -gx _fifc_unordered_comp $curr_fifc_unordered_comp set -gx _fifc_unordered_comp $curr_fifc_ordered_comp -rm $_fifc_complist_path +$fifc_rm_cmd $_fifc_complist_path