Closed ziranjameshe closed 7 months ago
Hi
The way to do this is documented in this section: https://github.com/lincheney/fzf-tab-completion#specifying-custom-fzf-options
In your case, you want to do --preview='eval cat {1}'
ah actually are you using bash? On bash it is a bit different, let me see if i can get it
Hey, yes, it's bash.
4.4.20
I may change this later to work more like the zsh one.
But for now, you should be able to workaround it by doing --preview='cat {1}{2}'
where {1}{2}
combined provide the full string.
Hey, thanks for the quick reply. I am not sure this fixes the issue.
When fzf
export here export FZF_DEFAULT_OPTS="--preview 'cat {}'"
being used, to me, the issue seems to be that when parsing the string in fzf-tab-completion
, some hidden characters got mangled in.
The preview option in the fzf opened window works fine. Just not working with fzf-tab-completion
. Also, if we just echo out the string, it also displays fine. I suspect it's some bash weirdness.
The \001
is actually being inserted by fzf-tab-completion
deliberately (https://github.com/lincheney/fzf-tab-completion/blob/master/bash/fzf-bash-completion.sh#L1 https://github.com/lincheney/fzf-tab-completion/blob/master/bash/fzf-bash-completion.sh#L336)
The reason it does this is to separate the prefix and the rest of the string, so that fzf will only search the suffix.
So if you had some files abc-abc
and abc-xyz
and you tried to complete with ls abc<tab>
, then abc
is the prefix
and each string gets turned into something like abc\001-abc
and abc\001-xyz
with the \001
as delimiter.
The reason for this is so that typing into the fzf prompt only searches in the suffix, or the part after that delimiter ie -abc
and -xyz
,
it will not search in the prefix abc
as you have already typed that before invoking tab completion.
If you were to type abc
into the fzf prompt, it would only show you abc-abc
as the match.
You may also notice when you do this the prefix should be highlighted differently in fzf.
For the preview option, {}
is giving it the entire string including the \001
delimiter,
but when you do {1}{2}
this is the prefix and suffix but without the delimiter.
Ahh, I see. Thank you!
Just out of curiosity, I tried to sed
and tr
the value I got from --preview foo {}
, but I can't get rid of the chars. Do you know why is that?
Yeah, just tested this. Works fine now. Thanks again for the quick turnaround.
I am happy with this WA, so please feel free to close the issue.
And thanks for the project, it's a great tool!
How to reproduce
Then using any command with preview window to preview a file will show
now sure where is
''$'\001''
coming from.sed
ortr
won't get rid of this.