zsh-users
 help / color / mirror / Atom feed
* Unable to successfully set up FZF_DEFAULT_COMMAND
@ 2021-08-30  0:36 Steve Dondley
  2021-08-30  1:26 ` Lawrence Velázquez
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Dondley @ 2021-08-30  0:36 UTC (permalink / raw)
  To: zsh users

I'm running MacOS on a fresh user install.

I'm trying to integrate the 'rg' command with fzf. The README page for 
fzf says to insert the following line into .zshrc:

INITIAL_QUERY=""
RG_PREFIX="rg --column --line-number --no-heading --color=always 
--smart-case "
FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
   fzf --bind "change:reload:$RG_PREFIX {q} || true" \
       --ansi --disabled --query "$INITIAL_QUERY" \
       --height=50% --layout=reverse

When I do add these lines, there are two problems:

1) When I reload zsh, the fzf command gets run with the rg command 
immediately.
2) When I type 'echo $FZF_DEFAULT_COMMAND' at the command prompt, the 
FZF_DEFAULT_COMMAND is not set. And then when I run 'fzf', I'll just get 
the default fzf behavior.

When I try adding the "export" keyword to export the FZF_DEFAULT_COMMAND 
but that results in an error:

/Users/test/.zshrc:export:3: not valid in this context: --bind. And 
'echo $FZF_DEFAULT_COMMAND' shows just:

rg --column --line-number --no-heading --color=always --smart-case  ''

I've searched around a great deal but I'm coming up empty. Can someone 
explain why I can't get this working?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unable to successfully set up FZF_DEFAULT_COMMAND
  2021-08-30  0:36 Unable to successfully set up FZF_DEFAULT_COMMAND Steve Dondley
@ 2021-08-30  1:26 ` Lawrence Velázquez
  2021-08-30  1:51   ` Steve Dondley
  0 siblings, 1 reply; 3+ messages in thread
From: Lawrence Velázquez @ 2021-08-30  1:26 UTC (permalink / raw)
  To: Steve Dondley; +Cc: zsh-users

On Sun, Aug 29, 2021, at 8:36 PM, Steve Dondley wrote:
> I'm running MacOS on a fresh user install.
> 
> I'm trying to integrate the 'rg' command with fzf. The README page for 
> fzf says to insert the following line into .zshrc:

I assume you're referring to this?  It doesn't say anything about
.zshrc.

https://github.com/junegunn/fzf#3-interactive-ripgrep-integration

> INITIAL_QUERY=""
> RG_PREFIX="rg --column --line-number --no-heading --color=always 
> --smart-case "
> FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
>    fzf --bind "change:reload:$RG_PREFIX {q} || true" \
>        --ansi --disabled --query "$INITIAL_QUERY" \
>        --height=50% --layout=reverse
> 
> When I do add these lines, there are two problems:
> 
> 1) When I reload zsh, the fzf command gets run with the rg command 
> immediately.
> 2) When I type 'echo $FZF_DEFAULT_COMMAND' at the command prompt, the 
> FZF_DEFAULT_COMMAND is not set. And then when I run 'fzf', I'll just get 
> the default fzf behavior.

Indeed.  The command you quoted is of the form

    FOO=bar cmd arg1 arg2 arg3

which runs cmd with FOO in its environment.  FOO is (generally) not
put into the environment of the executing shell.  (In your example,
"cmd" is fzf and "FOO" is FZF_DEFAULT_COMMAND.)

I'm not familiar with fzf or how it's intended to be used, but the
fact that that command runs fzf immediately makes me think it's not
supposed to go into a shell startup file.

> When I try adding the "export" keyword to export the FZF_DEFAULT_COMMAND 
> but that results in an error:
> 
> /Users/test/.zshrc:export:3: not valid in this context: --bind. And 
> 'echo $FZF_DEFAULT_COMMAND' shows just:
> 
> rg --column --line-number --no-heading --color=always --smart-case  ''

You took

    FOO=bar cmd arg1 arg2 arg3

and turned it into

    export FOO=bar cmd arg1 arg2 arg3

which exports FOO.  In your example it also exports a variable named
"fzf".  The other arguments become arguments to the export command
itself, which causes some trouble.

> I've searched around a great deal but I'm coming up empty. Can someone 
> explain why I can't get this working?

Perhaps you want this section?  You will have to adapt their example
to use ripgrep instead of fd.

https://github.com/junegunn/fzf#respecting-gitignore

-- 
vq


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unable to successfully set up FZF_DEFAULT_COMMAND
  2021-08-30  1:26 ` Lawrence Velázquez
@ 2021-08-30  1:51   ` Steve Dondley
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Dondley @ 2021-08-30  1:51 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: zsh-users

> I assume you're referring to this?  It doesn't say anything about
> .zshrc.

Indeed! So I simply dropped the example code into an executable at ~/bin 
and run that. It works perfectly. The fact that it ran when I reloaded 
zsh should have been a big clue but I'm new to zsh so I'm a little 
disoriented.

Thanks for your help and explanation!


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-30  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-30  0:36 Unable to successfully set up FZF_DEFAULT_COMMAND Steve Dondley
2021-08-30  1:26 ` Lawrence Velázquez
2021-08-30  1:51   ` Steve Dondley

zsh-users

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/zsh-users

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-users zsh-users/ https://inbox.vuxu.org/zsh-users \
		zsh-users@zsh.org
	public-inbox-index zsh-users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git