gokcehan / lf

Terminal file manager
MIT License
7.57k stars 322 forks source link

Option to set previewer only for binary files #322

Open kisscool opened 4 years ago

kisscool commented 4 years ago

Currently the user is forced to chose between using the default built-in previewer (from nav.go) or to delegate all the preview operations to an external program (like a custom script, bat or pistol). The thing is the built-in previewer is really fast and efficient for all text files, and it is a shame to disable it entirely in order to be able to do some custom preview operations on binary files.

An interesting middle-ground would be to have an option to use the previewer script only if the built-in previewer does not know how to decode the file.

gokcehan commented 4 years ago

@kisscool What do you mean by decoding the file? What ind of custom preview operations you have in mind for binary files?

kisscool commented 4 years ago

At https://github.com/gokcehan/lf/blob/c49140ab364cdb2773e3593dea6cfc72da4f1bb2/nav.go#L459 if the buf.Text() returns 0 then lf considers the internal previewer cannot decode the file and just write "\033[7mbinary\033[0m". My proposition is to create a configuration option to call a user defined previewer script when this case happen instead of just writing "\033[7mbinary\033[0m". What to do as binary file previewing would still be left to the user choice and imagination, but the previewing of text files would benefit from the speed of the internal lf routine.

As an example I wrote some of my previewings here. It bugs me to be obliged to call less for each text file while I know lf is perfectly able to do it with one less fork.

gokcehan commented 4 years ago

@kisscool I'm asking about your imagination for how to display a binary file. Binary files are not much meant to be displayed to humans, so I wonder what you have in mind.

kisscool commented 4 years ago

I often find myself checking the metadata of binary files : listing of video/audio/subtitles streams in video files, tags in audio files, exif informations in pictures... Those kind of informations are often useful when you are organizing or browsing a file collection (activities for which lf is perfect) and at the same time the parsing of those informations is better left to more specialized tools. Hence my proposal above.

mvllow commented 1 year ago

Just ran into this after getting image previews working in kitty terminal. E.g. text files no longer show a preview.

It would be lovely if the default lf previewer could be used for all non-image types in the above example.