sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
49.71k stars 1.25k forks source link

Support For Property List (PList) Format #2247

Open Gerst20051 opened 2 years ago

Gerst20051 commented 2 years ago

Syntax Highlighting For The Output From defaults read

[$]> defaults read com.googlecode.iterm2

{
    AppleAntiAliasingThreshold = 1;
    "Default Bookmark Guid" = "AD854671-C976-4C5D-9EA2-BD69DF273EF4";
    "NSSplitView Subview Frames NSColorPanelSplitView" =     (
        "0.000000, 0.000000, 224.000000, 258.000000, NO, NO",
        "0.000000, 259.000000, 224.000000, 48.000000, NO, NO"
    );
    "NSToolbar Configuration com.apple.NSColorPanel" =     {
        "TB Is Shown" = 1;
    };
    "iTerm Version" = "3.4.15";
}

https://en.wikipedia.org/wiki/Property_list

I believe this has already been implemented in some other tools! They appear to be using the same file.

Textmate

https://github.com/textmate/property-list.tmbundle/blob/textmate-1.x/Syntaxes/Property%20List.tmLanguage

Sublime

https://github.com/tyrone-sudeium/st3-binaryplist/blob/master/Property_List.tmLanguage

Delta Issue https://github.com/dandavison/delta/issues/1132

keith-hall commented 2 years ago

Are those tmLanguage files not for the xml plist format? This syntax is generally used in Sublime Text for that: https://github.com/SublimeText/PackageDev/blob/69a906404fdb9401bb192078cb81759206c45a83/Package/Property%20List/Property%20List.sublime-syntax

That text you provided doesn't look like any plist I have ever seen. Some kinda json hybrid? :) yeah, from the wiki page you linked, I'm guessing its NSJSONSerialization.

Gerst20051 commented 2 years ago

Thanks @keith-hall for pointing out NSJSONSerialization! I think that's a great search term to use!

I'll keep searching but I did find this file that builds the output for that:

https://github.com/microsoft/NSPlist/blob/6f6cfc785f258147b3234c8b42654b2b053d6a55/src/NSPlist.cpp#L158-L170

Alhadis commented 2 years ago

That text you provided doesn't look like any plist I have ever seen.

This is the original property list format used by NeXTSTEP, which was the Unix-like OS that became the foundation of Mac OS/X (i.e., Darwin). Apple switched to an XML-based format for their .plist files though, a decision I wish I could kick them for.

You'll see the original plist format referred to variously as "old-style property lists", "ASCII property lists", or "OpenStep property lists" (the latter used on GitHub). Some programs and APIs in macOS (most notably defaults) still read or emit data formatted in the OG property list format.

If you want syntax highlighting, I have good news: TextMate's own plist grammar has excellent highlighting support. But you'll need to support other TextMate-compatible grammar files in order to make use of it. 😛

Some kinda json hybrid?

It's actually older than JSON, and also a much nicer format to read and write. 😁