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

Reload command does not use the SHELL #3355

Closed
5 of 10 tasks
avdv opened this issue Jul 4, 2023 · 3 comments
Closed
5 of 10 tasks

Reload command does not use the SHELL #3355

avdv opened this issue Jul 4, 2023 · 3 comments

Comments

@avdv
Copy link

avdv commented Jul 4, 2023

  • I have read through the manual page (man fzf)
  • I have the latest version of fzf (0.42.0 (d471067))
  • I have searched through the existing issues

Info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

From reading the man page and looking at #1750 I got the idea that one could use FZF_DEFAULT_COMMAND in the reload action, but that does not work like advertised:

export FZF_DEFAULT_COMMAND='echo "test"' SHELL=bash

fzf  --bind 'ctrl-r:reload:$FZF_DEFAULT_COMMAND' --preview 'echo $FZF_DEFAULT_COMMAND'

When run, this displays test in the result list. When hitting ctrl-r it displays "test" (including the quotes).

So in order to use the FZF_DEFAULT_COMMAND in reload you would have to pass it to the SHELL explicitly:

export FZF_DEFAULT_COMMAND='echo "test"' SHELL=bash

fzf  --bind 'ctrl-r:reload:$SHELL -c "$FZF_DEFAULT_COMMAND"' --preview 'echo $FZF_DEFAULT_COMMAND'
@LangLangBart
Copy link
Contributor

When run, this displays test in the result list. When hitting ctrl-r it displays "test" (including the quotes).

fzf  --bind 'ctrl-r:reload:eval $FZF_DEFAULT_COMMAND'

So in order to use the FZF_DEFAULT_COMMAND in reload you would have to pass it to the SHELL explicitly:

export FZF_DEFAULT_COMMAND='echo "test"' SHELL=bash

fzf  --bind 'ctrl-r:reload:$SHELL -c "$FZF_DEFAULT_COMMAND"' --preview 'echo $FZF_DEFAULT_COMMAND'
  • seems to be superfluous, because fzf already does that by using $SHELL -c COMMAND
man fzf
# FZF_DEFAULT_COMMAND
#   Default command to use when input is tty. On *nix  systems,  fzf runs the command
#   with $SHELL -c if SHELL is set, otherwise with sh -c, so in this case make sure
#   that the command is POSIX-compliant.

@junegunn
Copy link
Owner

fzf does use $SHELL.

When run, this displays test in the result list. When hitting ctrl-r it displays "test" (including the quotes).

You'll get the same result if you do the same on bash

bash

$ export FZF_DEFAULT_COMMAND='echo "test"'
$ $FZF_DEFAULT_COMMAND
"test"

So, use eval as suggested by @LangLangBart

$ eval "$FZF_DEFAULT_COMMAND"
test

@avdv
Copy link
Author

avdv commented Jul 12, 2023

Thank you. Yes, you are right. I quickly run fzf with strace and didn't spot the bash -c call somehow (probably because I was looking for the wrong thing).

The confusion (and different behavior) just comes from the fact that when setting FZF_DEFAULT_COMMAND fzf already gets the value of the variable and then calls $SHELL -c <value> whereas inside the reload command it literally calls $SHELL -c $FZF_DEFAULT_COMMAND.

The example from #1750 makes it look like those two things should be identical:

FZF_DEFAULT_COMMAND='find . -type f' fzf \
  --bind 'ctrl-d:reload(find . -type d),ctrl-f:reload($FZF_DEFAULT_COMMAND)'

It would help to call this out more explicitly.

That one needs to evaluate the variable manually, either by using bash -c $FZF_DEFAULT_COMMAND or eval $FZF_DEFAULT_COMMAND or just letting the shell expand the variable in the --bind call directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants