feat: respect XDG_DATA_HOME when searching for desktop files

This commit is contained in:
imgurbot12 2024-04-08 02:54:43 -07:00
parent 8e01e98bc3
commit 108e5272fc

View File

@ -8,8 +8,11 @@ use rmenu_plugin::{Action, Entry, Method};
mod icons; mod icons;
static XDG_HOME_ENV: &'static str = "XDG_DATA_HOME";
static XDG_DATA_ENV: &'static str = "XDG_DATA_DIRS"; static XDG_DATA_ENV: &'static str = "XDG_DATA_DIRS";
static XDG_CONFIG_ENV: &'static str = "XDG_CONFIG_HOME"; static XDG_CONFIG_ENV: &'static str = "XDG_CONFIG_HOME";
static XDG_HOME_DEFAULT: &'static str = "~/.local/share";
static XDG_DATA_DEFAULT: &'static str = "/usr/share:/usr/local/share"; static XDG_DATA_DEFAULT: &'static str = "/usr/share:/usr/local/share";
static XDG_CONFIG_DEFAULT: &'static str = "~/.config"; static XDG_CONFIG_DEFAULT: &'static str = "~/.config";
@ -25,8 +28,9 @@ fn config_dir() -> PathBuf {
/// Retrieve XDG-DATA Directories /// Retrieve XDG-DATA Directories
fn data_dirs(dir: &str) -> Vec<PathBuf> { fn data_dirs(dir: &str) -> Vec<PathBuf> {
std::env::var(XDG_DATA_ENV) let home = std::env::var(XDG_HOME_ENV).unwrap_or_else(|_| XDG_HOME_DEFAULT.to_string());
.unwrap_or_else(|_| XDG_DATA_DEFAULT.to_string()) let dirs = std::env::var(XDG_DATA_ENV).unwrap_or_else(|_| XDG_DATA_DEFAULT.to_string());
format!("{home}:{dirs}")
.split(":") .split(":")
.map(|p| shellexpand::tilde(p).to_string()) .map(|p| shellexpand::tilde(p).to_string())
.map(PathBuf::from) .map(PathBuf::from)