Skip to content

Env var / dynamic way to determine the preview hidden state within a transformer #4098

Closed
@ibhagwan

Description

@ibhagwan

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.56.2

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

Context: #3817 (comment).

Consider the example (from the above link):

TRANSFORMER='
  echo -n change-preview-window:
  if ((100 * FZF_COLUMNS / FZF_LINES >= 150)) && ((FZF_COLUMNS >= 120)); then
    echo "right,50%,border-left"
  elif ((FZF_LINES >= 40)); then
    echo "up,30%,border-bottom"
  else
    echo "hidden"
  fi
'

fzf --bind "start:transform($TRANSFORMER),resize:transform($TRANSFORMER)" --preview 'cat {}' --preview-window=hidden

There are a couple of issues with this:

  • When running the above the transfomer doesn't take into account the preview hidden state, due to the transform running on start, the previewer opens in a visible state even though we specify hidden
  • Hiding the previewer with a keybind and resizing the terminal causes the previewer to unhide

I tried the below transformer (using FZF_PREVIEW_COLUMNS) but the previewer opens hidden and also hides itself when triggering resize:

TRANSFORMER='
  echo -n change-preview-window:
  if ((FZF_PREVIEW_COLUMNS == 0)) then
      echo "hidden"
  elif ((100 * FZF_COLUMNS / FZF_LINES >= 150)) && ((FZF_COLUMNS >= 120)); then
    echo "right,50%,border-left"
  elif ((FZF_LINES >= 40)); then
    echo "up,30%,border-bottom"
  else
    echo "hidden"
  fi
'

Am I missing something? Is there an env var I can use to determine if the previewer is hidden?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions