4 releases
new 0.1.3 | Feb 19, 2025 |
---|---|
0.1.2 | Feb 18, 2025 |
0.1.1 | Feb 17, 2025 |
0.1.0 | Feb 17, 2025 |
#601 in Filesystem
72 downloads per month
64KB
1K
SLoC
Freedesktop Desktop Entry Parser
A Rust library for parsing and manipulating Linux .desktop
files according to the freedesktop.org Desktop Entry Specification.
Features
- Full support for Desktop Entry Specification v1.5
- Locale-aware string handling
- Icon resolution using freedesktop icon theme
- Support for desktop actions
- Strong type safety with Rust's type system
Usage
Add this to your Cargo.toml
:
[dependencies]
freedesktop-file-parser = "0.1.0"
Basic Example
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(())
}
Handling Localized Strings
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);
}
Working with Actions
// 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);
}
}
Supported Fields
The library supports all standard fields from the Desktop Entry Specification, including:
- Basic fields (Type, Name, GenericName, NoDisplay, Comment, Icon)
- Application fields (Exec, TryExec, Path, Terminal, MimeType, Categories)
- Startup fields (StartupNotify, StartupWMClass)
- Display fields (Hidden, OnlyShowIn, NotShowIn)
- Actions
- DBus activation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- freedesktop.org for the Desktop Entry Specification
- freedesktop-icons for icon resolution support
Status
This project is under active development. While it implements the full specification, please report any bugs or missing features.
Dependencies
~2–12MB
~82K SLoC