Skip to content

Commit

Permalink
✨ add xdg dir back
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Mar 9, 2024
1 parent 580d20c commit bbc5937
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 81 deletions.
127 changes: 92 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
url = "2.1"
vsort = "0.2"
xdg = "2.5"

[target."cfg(not(all(windows, target_arch = \"x86\", target_env = \"gnu\")))".dependencies]
# if ssl feature is enabled compilation will fail on arm-unknown-linux-gnueabihf and i686-pc-windows-gnu
Expand Down
9 changes: 8 additions & 1 deletion src/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,16 @@ impl Config {
/// `%APPDATA%\lsd` or `%USERPROFILE%\.config\lsd` in that order.
/// This will apply both to the config file and the theme file.
pub fn config_paths() -> impl Iterator<Item = PathBuf> {
#[cfg(not(windows))]
use xdg::BaseDirectories;

[
dirs::config_dir(),
dirs::home_dir().map(|h| h.join(".config")),
dirs::config_dir(),
#[cfg(not(windows))]
BaseDirectories::with_prefix("")
.ok()
.map(|p| p.get_config_home()),
]
.iter()
.filter_map(|p| p.as_ref().map(|p| p.join("lsd")))
Expand Down
9 changes: 6 additions & 3 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use std::os::unix::io::AsRawFd;
use crate::flags::blocks::Block;
use crate::git_theme::GitTheme;
#[cfg(target_os = "windows")]
use crate::meta::windows_utils;
#[cfg(target_os = "windows")]
use terminal_size::terminal_size;

pub struct Core {
Expand Down Expand Up @@ -107,7 +105,12 @@ impl Core {
};

#[cfg(target_os = "windows")]
let paths: Vec<PathBuf> = paths.into_iter().map(windows_utils::expand_home).collect();
use crate::config_file;
#[cfg(target_os = "windows")]
let paths: Vec<PathBuf> = paths
.into_iter()
.filter_map(config_file::expand_home)

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

cannot find value `expand_home` in module `config_file`

Check failure on line 112 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

cannot find value `expand_home` in module `config_file`
.collect();

for path in paths {

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Style (windows-latest)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-gnu)

the size for values of type `[u8]` cannot be known at compilation time

Check failure on line 115 in src/core.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

the size for values of type `[u8]` cannot be known at compilation time
let mut meta =
Expand Down
14 changes: 1 addition & 13 deletions src/meta/windows_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::{OsStr, OsString};
use std::io;
use std::mem::MaybeUninit;
use std::os::windows::ffi::{OsStrExt, OsStringExt};
use std::path::{Path, PathBuf};
use std::path::Path;

use windows::Win32::Foundation::PSID;
use windows::Win32::Security::{self, Authorization::TRUSTEE_W, ACL};
Expand Down Expand Up @@ -343,18 +343,6 @@ pub fn is_path_system(path: &Path) -> bool {
)
}

/// Expands the `~` in a path to the current user's home directory
pub fn expand_home(path: PathBuf) -> PathBuf {
if path.starts_with("~") {
if let Some(home) = dirs::home_dir() {
let mut expanded = home.to_path_buf();
expanded.push(path.strip_prefix("~").unwrap());
return expanded;
}
}
path
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading

0 comments on commit bbc5937

Please sign in to comment.