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

Trouble getting the reload with transform correctly #4246

Closed
rbhanot4739 opened this issue Feb 15, 2025 · 4 comments
Closed

Trouble getting the reload with transform correctly #4246

rbhanot4739 opened this issue Feb 15, 2025 · 4 comments

Comments

@rbhanot4739
Copy link

rbhanot4739 commented Feb 15, 2025

Hello,

I am not sure if this is a bug or just something wrong with the way I am doing things, so apologies in advance for that. Please consider the below query

❯ ls -l |grep py | fzf --prompt 'Files> ' --bind '?:transform:[[ ! $FZF_PROMPT =~ Files ]] && echo "change-prompt(Files> )+reload(ls -l | grep py)" || echo "change-prompt(Zoxide> )+reload(zoxide query -l | head -n 10 | xargs -I {} basename {})"'

and here is how it behaves: as I could observe this happens due to the exit status of the ls -l |grep py being non-zero since no match was found but why would that interfere with the second reload query ?

rec1.mp4

And here is how it behaves when I reverse the grep pattern

ls -l |grep -v py | fzf --prompt 'Files> ' --bind '?:transform:[[ ! $FZF_PROMPT =~ Files ]] && echo "change-prompt(Files> )+reload(ls -l | grep -v py)" || echo "change-prompt(Zoxide> )+reload(zoxide query -l | head -n 10 | xargs -I {} basename {})"'
rec2.mp4

So I am not sure how do I handle this or what is the right way of doing this.

@junegunn
Copy link
Owner

A common mistake when writing a lengthy transform script is not escaping the placeholders, making them evaluated right away.

Can you try escaping {} to \{} in your script?

@rbhanot4739
Copy link
Author

I tried with escaping the {} as well but it didn't work.. infact escaping \{} makes the second reload zoxide does not evaluate at all.

 ls -l |grep py | fzf --prompt 'Files> ' --bind '?:transform:[[ ! $FZF_PROMPT =~ Files ]] && echo "change-prompt(Files> )+reload(ls -l | grep py)" || echo "change-prompt(Zoxide> )+reload(zoxide query -l | head -n 10 | xargs -I \{} basename \{})"'

WIth above when I press ? the zoxide query does not get executed.

@junegunn
Copy link
Owner

I think you shouldn't be using {} as a placeholder expression for xargs, as it makes things really hard to comprehend. Try something like xargs -I {x} basename {x} not to make fzf's evaluation happen at all at any stage.

@rbhanot4739
Copy link
Author

@junegunn Thank you helping patiently, {x} indeed did the trick.

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

2 participants