#linux #icons #freedesktop

freedesktop_entry_parser

A library for parsing FreeDesktop entry files

7 releases (2 stable)

1.1.0 Aug 11, 2020
1.0.0 Jul 25, 2020
0.4.1 Jul 24, 2020
0.2.2 May 15, 2020
0.1.0 Feb 28, 2020

#74 in Unix APIs

Download history 16/week @ 2020-06-25 13/week @ 2020-07-02 19/week @ 2020-07-09 7/week @ 2020-07-16 73/week @ 2020-07-23 32/week @ 2020-07-30 80/week @ 2020-08-06 46/week @ 2020-08-13 36/week @ 2020-08-20 30/week @ 2020-08-27 45/week @ 2020-09-03 17/week @ 2020-09-10 18/week @ 2020-09-17 27/week @ 2020-09-24 31/week @ 2020-10-01 25/week @ 2020-10-08

139 downloads per month
Used in 4 crates (3 directly)

MPL-2.0 license

37KB
808 lines

Freedesktop Entry Parser

crates.io docs.rs

A library for parsing FreeDesktop entry files in Rust. These files are used in the Desktop Entry, Icon Theme, and Systemd Unit file. They are similar to ini files but are distinct enough that an ini parse would not work.

Example Usage

As example input lets use the contents of sshd.service

[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target

[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target

For example, to print the start command we could do this:

use freedesktop_entry_parser::parse_entry;

let entry = parse_entry("./test_data/sshd.service")?;
let start_cmd = entry
    .section("Service")
    .attr("ExecStart")
    .expect("Attribute doesn't exist");
println!("{}", start_cmd);

# Ok::<(), freedesktop_entry_parser::ParseError>(())

This prints /usr/bin/sshd -D

For more extensive documentaion see docs.rs or generate the docs yourself by cloning the repo and running cargo doc. For more examples see the exmaples in the repo.

Dependencies

~1.1–1.6MB
~35K SLoC