Skip to content

Intelligent support for LESSOPEN and LESSCLOSE #1739

@lilyball

Description

@lilyball

macOS has 3 different plist formats, two of them textual (NeXTStep and XML) and one binary. The textual plists are human-readable already, but the binary one isn't, and trying to run bat on it just warns me that it's a binary file.

What I'd really like is a way to configure bat to run plists through plutil -p to get a human-readable textual output. It could note that the file has been preprocessed this way in the header. And there should be an easy way to disable this (such as a flag that says "disable file preprocessors"). This would be similar to LESSOPEN (which has the flag -L to disable it), except defined on a per–file extension basis rather than being a global option that requires the script to decide what to do (this way bat can know and display whether the file has been preprocessed).

Optionally, this plutil -p preprocessing could be done only for binary files, this way running bat on an XML plist would show the XML. I'm not sure whether this is a good idea. This approach could then mean the flag to disable preprocessing could look like --preprocess=always|binary|never, though I suppose having that as a global option is unfortunate if I want to only preprocess binary plists but always preprocess some other file type. I'm not aware of any precedent for setting per-language options though (just for mapping file globs to syntax names). Perhaps the syntax to define a preprocessor could allow for selecting whether it should only apply to binary files. Or maybe the preprocessor itself should just be a script that makes that call, though in this case bat doesn't know whether the file has been modified (which seems like a very useful thing to know for displaying in the header). Or maybe this is just overcomplicating it and a preprocessor should just be defined for a file pattern and I can use the appropriate flag to disable it if I want to see the original file.

Side note: if bat ever becomes a pager in its own right instead of relying on less it could then have an interactive option to toggle the preprocessor off or on.

Also, while I've been talking about plists, I could imagine this ability being useful for e.g. displaying metadata about images or videos, or displaying some sort of summary of sqlite files, or other similar preprocessors.

Alternatives

While a generic preprocessor feature seems useful, as an alternative bat could simply bake in knowledge of plists on macOS only (along with a macOS-only flag to disable plist transformations). It could either still just run them through plutil -p, or it could call into CoreFoundation to parse the plist directly, though I'm not aware offhand of any way to get the plutil -p output format that way without reimplementing it by hand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions