PatrickF1 / fzf.fish

🔍🐟 Fzf plugin for Fish
MIT License
1.92k stars 76 forks source link

Do `fzf_preview_dir_cmd` and `fzf_preview_file_cmd` need to be exported? #305

Closed TheFunctionalGuy closed 11 months ago

TheFunctionalGuy commented 11 months ago

Describe the bug

Using set fzf_preview_dir_cmd exa --all --color=always or set fzf_preview_file_cmd cat -n in config.fish has no effect on the actual preview.

To fix this I needed to use set --export fzf_preview_dir_cmd exa --all --color=always instead.

Steps to reproduce

  1. Add set fzf_preview_dir_cmd exa --all --color=always to your config.fish
  2. Start new shell so that config.fish gets sourced
  3. Press Ctrl+Alt+F
  4. Get no colored exa output but the plain ls -F -A output that's default

Environment

Versions installed:

Additional context

Fix

This can easily fixed by adding set --export the the variables. Is this intentionally? If so I would propose to add this to the documentation.

PatrickF1 commented 11 months ago

Hi again, thanks for filing a bug! I think it might be because your config.fish depends on whether you are in interactive mode or non-interactive. Do you have something like status is-interactive || exit and beneath it the two variables are set?

TheFunctionalGuy commented 11 months ago

Hi, you are correct.

My config looks like this:

if status is-interactive
    # Commands to run in interactive sessions can go here
    # Set editor to neovim
    set --global --export EDITOR nvim

    # Initialize zoxide
    type --query zoxide && zoxide init fish | source

    # Custom settings for "tide" theme
    set --global fish_greeting

    # Custom settings for fzf.fish
    set fzf_directory_opts --bind "ctrl-o:execute($EDITOR {} &>/dev/tty)"
    set --export fzf_preview_dir_cmd exa --all --color=always
    fzf_configure_bindings --git_log=\e\cg

    # Cursor settings
    set fish_cursor_default block
    set fish_cursor_insert line
    set fish_cursor_replace_one underscore
    set fish_cursor_replace underscore

    # Abbreviations
    # Editor
    abbr --add n nvim
    abbr --add se sudoedit

    # Exa
    abbr --add ll exa -l
    abbr --add la exa -la
    abbr --add lt exa -T
    abbr --add l exa

    # Git
    abbr --add gf git fetch
    abbr --add gp git pull
    abbr --add gP git push
    abbr --add gs git status
    abbr --add gc git commit
    abbr --add gcm --set-cursor 'git commit -m "%'
    abbr --add gd git diff
    abbr --add gds git diff --staged
    abbr --add ga git add
    abbr --add gr git restore
    abbr --add grs git restore --staged
    abbr --add gl git log
    abbr --add lg lazygit

    # Leetcode
    abbr --add lc leetcode

    # Misc
    type --query just && abbr --add j just
    type --query paru && abbr --add p paru

    # Updating
    type --query pacman && abbr --add up sudo pacman -Syu
    type --query paru && abbr --add up paru
    type --query eos-update && abbr --add up eos-update --paru

    # nnn colors
    set --export NNN_COLORS 1324
    set --export NNN_FCOLORS 020b040a00050ef7c6d6abc4
    set --export NNN_PLUG "c:fzcd;f:rg-fzf;r:gitroot;z:autojump"
    set --export NNN_TRASH 1

    # Multicd parameter
    function _multicd_parameter
        echo (string join "" (string repeat -n (math (string length -- $argv[1]) - 1) ../) '%')
    end
    abbr --add multicd_parameter --set-cursor --position anywhere --regex '^\.\.+$' --function _multicd_parameter

    # Multicd
    function _multicd
        echo cd (string repeat -n (math (string length -- $argv[1]) - 1) ../)
    end
    abbr --add multicd --position command --regex '^\.\.+$' --function _multicd

    # Replace !! by last history (for easier sudo repeat)
    function _last_history_item
        echo $history[1]
    end
    abbr -a !! --position anywhere --function _last_history_item
end

So the variables aren't set when called inside the fzf_wrapper because it's not considered interactive?

I should've informed myself about status is-interactive better. Might still be a good idea to note that in the docs.

PatrickF1 commented 11 months ago

So the variables aren't set when called inside the fzf_wrapper because it's not considered interactive?

The reason it wasn't working for you is because when fzf spawns a new fish proccess, it does not attach it to a TTY so fish considers it non-interactive mode, so your set commands don't trigger. The export fixed this because it was explicitly inserted into the new fish shell's environment.

Might still be a good idea to note that in the docs.

Maybe. I'll keep thinking about this, because your case is quite unusual and I have to balance it with not overwhelming the readers.