mirror of
https://github.com/imgurbot12/rmenu.git
synced 2024-11-10 11:33:48 +01:00
feat: hide duplicate desktop files by default
This commit is contained in:
parent
ab1b68e7db
commit
e6b8018cb5
@ -6,9 +6,9 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.9", features = ["derive"] }
|
||||
freedesktop-desktop-entry = "0.5.2"
|
||||
freedesktop-icons = "0.2.6"
|
||||
log = "0.4.21"
|
||||
itertools = "0.13.0"
|
||||
once_cell = "1.19.0"
|
||||
rayon = "1.10.0"
|
||||
regex = "1.10.4"
|
||||
|
@ -1,7 +1,9 @@
|
||||
use std::fs::read_to_string;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
use freedesktop_desktop_entry::{DesktopEntry, Iter};
|
||||
use itertools::Itertools;
|
||||
use once_cell::sync::Lazy;
|
||||
use rayon::prelude::*;
|
||||
use regex::Regex;
|
||||
@ -117,7 +119,15 @@ fn assign_icon(icon: String, map: &icons::IconMap) -> Option<String> {
|
||||
Some(icon)
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Cli {
|
||||
/// Only Allow Unique Desktop Entries
|
||||
#[clap(short, long)]
|
||||
non_unique: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let locale = Some("en");
|
||||
let sizes = vec![64, 32, 96, 22, 128];
|
||||
|
||||
@ -130,6 +140,13 @@ fn main() {
|
||||
let app_paths = data_dirs("applications");
|
||||
let mut desktops: Vec<Entry> = Iter::new(app_paths)
|
||||
.into_iter()
|
||||
.unique_by(|f| match cli.non_unique {
|
||||
true => f.to_str().map(|s| s.to_owned()),
|
||||
false => f
|
||||
.file_name()
|
||||
.and_then(|n| n.to_str())
|
||||
.map(|s| s.to_string()),
|
||||
})
|
||||
.filter_map(|f| parse_desktop(&f, locale))
|
||||
.map(|mut e| {
|
||||
e.icon = e.icon.and_then(|s| assign_icon(s, &icons));
|
||||
|
Loading…
Reference in New Issue
Block a user