| Crates.io | freedesktop-file-parser |
| lib.rs | freedesktop-file-parser |
| version | 0.3.1 |
| created_at | 2025-02-17 18:33:29.78388+00 |
| updated_at | 2025-07-21 10:05:50.190399+00 |
| description | Freedesktop Desktop Entry Parser |
| homepage | |
| repository | https://github.com/BL-CZY/desktop_file_parser |
| max_upload_size | |
| id | 1559216 |
| size | 73,526 |
A Rust library for parsing and manipulating Linux .desktop files according to the freedesktop.org Desktop Entry Specification.
Add this to your Cargo.toml:
[dependencies]
freedesktop-file-parser = "0.3.0"
use freedesktop_file_parser::{parse, EntryType};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let content = r#"[Desktop Entry]
Type=Application
Name=Firefox
Exec=firefox %u
Icon=firefox
Categories=Network;WebBrowser;
"#;
let desktop_file = parse(content)?;
// Access basic properties
println!("Name: {}", desktop_file.entry.name.default);
// Check entry type
if let EntryType::Application(app) = &desktop_file.entry.entry_type {
println!("Exec: {}", app.exec.as_ref().unwrap());
}
Ok(())
}
use freedesktop_file_parser::LocaleString;
// Access different translations
if let Some(de_name) = desktop_file.entry.name.variants.get_variant("de") {
println!("German name: {}", de_name);
}
// Access application actions
for (action_name, action) in &desktop_file.actions {
println!("Action: {}", action.name.default);
if let Some(exec) = &action.exec {
println!("Action command: {}", exec);
}
}
The library supports all standard fields from the Desktop Entry Specification, including:
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is under active development. While it implements the full specification, please report any bugs or missing features.