lf icon indicating copy to clipboard operation
lf copied to clipboard

Dynamic set of previewer does not work for the first file

Open j-xella opened this issue 1 year ago • 2 comments

I have my own previewer script, which I keep in the lf config folder (because that's what I use it for).

Unfortunately, the config folder is not always located in ~/.config/lf. In some scenarios, I need to have the config folder elsewhere, which I do by redefining $XDG_CONFIG_HOME variable. To be able to use the same lfrc file everywhere, I set the previewer option in the following way in my lfrc:

&{{
  $lf -remote "send $id set previewer ${XDG_CONFIG_HOME:-~/.config}/lf/preview/previewer.pl"
}}

This generally works, but has a side effect of leaving the first file lf shows after start-up with a wrong preview. My understanding is that my way of setting the previewer just puts the command on the queue, and the previewer is only set at a later stage, when the preview of the first file has already been generated. And, once generated, the preview is cached, so nothing can be done about it...

How could I overcome this problem? It could be helped if any of the following was implemented:

  • Special way to specify lf config folder directly from the lf script. For example, lf is clever enough to replace ~ with path to home folder, so that the following works: set previewer ~/.config/lf/preview/previewer.pl. Is it possible to introduce some other special sequences for other folders? For example, in shells, ~user_id is expanded to a home folder of that particular user_id. I wonder if lf could do something similar, so that I could specify something like set previewer ~lf_config/preview/previewer.pl directly from lfrc, without spawning subshells (I hope the chance of having a user named lf_config is small...)
  • Is it possible to clear the preview cache and make lf regenerate it at runtime? For all files or for a current file in particular?

j-xella avatar Jun 20 '23 10:06 j-xella

OK, I have found the reload command - that takes care of cache cleaning:

&{{
  $lf -remote "send $id set previewer ${XDG_CONFIG_HOME:-~/.config}/lf/preview/previewer.pl"
  $lf -remote "send $id reload"
}} 

But having special folders expanded would still be very useful, in many scenarios ....

j-xella avatar Jun 20 '23 11:06 j-xella

Rather than using lf -remote to set the previewer option after lf has loaded, I think it might be better if you start lf using the -command option as these are executed before lf loads. The following code shows the order of initializations and you might be interested in it:

https://github.com/gokcehan/lf/blob/e885abe1a3f6a0a6a795f7f75f601c80566a3de2/app.go#L254-L287

As an extension to #1280, lf was designed to have a simple config file loading system, as most users only need a single config file, and a simple ~ expansion is merely provided as a convenience. If you need something more complex, maybe you can write a wrapper script that invokes lf with some computed values for the -config /-command options.

joelim-work avatar Jun 20 '23 12:06 joelim-work