Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do fzf_preview_dir_cmd and fzf_preview_file_cmd need to be exported? #305

Closed
TheFunctionalGuy opened this issue Aug 15, 2023 · 3 comments
Closed
Labels
not a bug The issue is not a bug within fzf.fish

Comments

@TheFunctionalGuy
Copy link

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:

  • Fish: 3.6.1
  • fzf.fish: 9.9
  • terminal: alacritty 0.12.2 (9d9982df)
  • OS: Linux, EndeavourOS, kernel 6.4.10-arch1-1
  • Configuration variables:
set fzf_directory_opts --bind "ctrl-o:execute($EDITOR {} &>/dev/tty)"
set fzf_preview_dir_cmd exa --all --color=always
fzf_configure_bindings --git_log=\e\cg

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 PatrickF1 changed the title set fzf_preview_dir_cmd exa --all --color=always has no effect in when set fzf_preview_dir_cmd and fzf_preview_file_cmd need to be exported Aug 15, 2023
@PatrickF1
Copy link
Owner

PatrickF1 commented Aug 15, 2023

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
Copy link
Author

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 PatrickF1 changed the title fzf_preview_dir_cmd and fzf_preview_file_cmd need to be exported Do fzf_preview_dir_cmd and fzf_preview_file_cmd need to be exported? Aug 16, 2023
@PatrickF1
Copy link
Owner

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.

@PatrickF1 PatrickF1 added the not a bug The issue is not a bug within fzf.fish label Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug The issue is not a bug within fzf.fish
Projects
None yet
Development

No branches or pull requests

2 participants