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

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

Closed
4 of 10 tasks
ibhagwan opened this issue Nov 17, 2024 · 4 comments
Closed
4 of 10 tasks

Comments

@ibhagwan
Copy link

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?

@junegunn
Copy link
Owner

No, there currently isn't a way. FZF_PREVIEW_* env vars are only exported to preview processes.

@ibhagwan
Copy link
Author

No, there currently isn't a way. FZF_PREVIEW_* env vars are only exported to preview processes.

Would you consider exporting these to the transform process? Could there be any downside?

@junegunn
Copy link
Owner

Will do. No downsides. The overhead for adding environment variables to other processes is going to be negligible.

@ibhagwan
Copy link
Author

Ty @junegunn!

tmeijn pushed a commit to tmeijn/dotfiles that referenced this issue Dec 21, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [junegunn/fzf](https://github.com/junegunn/fzf) | minor | `v0.56.3` -> `v0.57.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>junegunn/fzf (junegunn/fzf)</summary>

### [`v0.57.0`](https://github.com/junegunn/fzf/releases/tag/v0.57.0): 0.57.0

[Compare Source](junegunn/fzf@v0.56.3...v0.57.0)

-   You can now resize the preview window by dragging the border
-   Built-in walker improvements
    -   `--walker-root` can take multiple directory arguments. e.g. `--walker-root include src lib`
    -   `--walker-skip` can handle multi-component patterns. e.g. `--walker-skip target/build`
-   Removed long processing delay when displaying images in the preview window
-   `FZF_PREVIEW_*` environment variables are exported to all child processes ([#&#8203;4098](junegunn/fzf#4098))
-   Bug fixes in fish scripts

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS43Ny4wIiwidXBkYXRlZEluVmVyIjoiMzkuNzcuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants