0

I'm new to z shell and ohmyz.sh.

I have the following in my zshrc to integrate fzf with rg. This is exactly how it appears in the fzf readme:

FZF_BASE=/usr/local/bin
DISABLE_FZF_AUTO_COMPLETION="true"
DISABLE_FZF_KEY_BINDINGS="true"
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

It kind of works but I'm seeing some weird and broken behavior:

  1. The weird behavior is that when I reload zshell, fzf fires up immediately without me hitting a key or typing in the command. It works perfectly, otherwise, though.

  2. The broken behavior is that when I manually type in fzf, the search is initiated but FZF_DEFAULT_COMMAND is set to what the plugin uses.

I tried fixing this behavior by slapping export in front of FZF_DEFAULT_COMMAND but then when I reload zsh, I get an error:

/Users/me/.zshrc:export:313: not valid in this context: --bind

Next I turned the ohmyzsh plugin off and modified my code to this:

FZF_DEFAULT_COMMAND="$RG_PREFIX '$INITIAL_QUERY'" \
  fzf --bind "change:reload:$RG_PREFIX {q} || true" \
      --ansi --disabled --query "$INITIAL_QUERY" \
      --height=50% --layout=reverse
export FZF_DEFAULT_COMMAND

This kind of works, but again, it fires up fzf as soon as I load zsh. And the formatting of the search is mangled and ugly with ansi characters.

StevieD
  • 855
  • 2
  • 10
  • 23
  • This is seems related but I don't have an alias set up that I think might cause a conflict. But I'm not sure: https://github.com/junegunn/fzf/issues/1938 – StevieD Aug 29 '21 at 19:44

1 Answers1

0

OK, the problem was putting this code into .zshrc. It doesn't go there. It goes in a separate script file or function.

StevieD
  • 855
  • 2
  • 10
  • 23