mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 22:22:26 +00:00
Add support for tilde (~) expansion on windows
This commit is contained in:
parent
1e8120ff28
commit
a1bd4d6347
3 changed files with 19 additions and 1 deletions
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
configuration fields) to truncate user and group names if they exceed a certain number
|
||||
of characters (disabled by default).
|
||||
- Add support for `--literal` from [PanGan21](https://github.com/PanGan21)
|
||||
- Add support for tilde (`~`) expansion on Windows from [Ofer Sadan](https://github.com/ofersadan85)
|
||||
|
||||
## [v1.0.0] - 2023-08-25
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ 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 {
|
||||
|
@ -104,6 +106,9 @@ impl Core {
|
|||
_ => 1,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
let paths: Vec<PathBuf> = paths.into_iter().map(windows_utils::expand_home).collect();
|
||||
|
||||
for path in paths {
|
||||
let mut meta =
|
||||
match Meta::from_path(&path, self.flags.dereference.0, self.flags.permission) {
|
||||
|
|
|
@ -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;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use windows::Win32::Foundation::PSID;
|
||||
use windows::Win32::Security::{self, Authorization::TRUSTEE_W, ACL};
|
||||
|
@ -343,6 +343,18 @@ 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::*;
|
||||
|
|
Loading…
Reference in a new issue