mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
format [no ci]
This commit is contained in:
parent
4fb835ee64
commit
bc9fb8e302
1 changed files with 18 additions and 14 deletions
|
|
@ -7,23 +7,28 @@ use crate::Url;
|
||||||
pub fn expand_path(p: impl AsRef<Path>) -> PathBuf {
|
pub fn expand_path(p: impl AsRef<Path>) -> PathBuf {
|
||||||
let mut p = p.as_ref();
|
let mut p = p.as_ref();
|
||||||
|
|
||||||
// expand the environment variable by calling the "echo" command, in linux case, this also expands the '~' path
|
// expand the environment variable by calling the "echo" command, in linux case,
|
||||||
|
// this also expands the '~' path
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let expanded_path = match std::process::Command::new("cmd").args(&["/C", "echo"]).arg(p).output() {
|
let expanded_path = match std::process::Command::new("cmd").args(&["/C", "echo"]).arg(p).output() {
|
||||||
Ok(output) if output.status.success() => Some(String::from_utf8_lossy(&output.stdout)
|
Ok(output) if output.status.success() => Some(
|
||||||
.trim_end()
|
String::from_utf8_lossy(&output.stdout)
|
||||||
.trim_matches('"')
|
.trim_end()
|
||||||
.replace("\\\"", "\"")
|
.trim_matches('"')
|
||||||
.to_string()
|
.replace("\\\"", "\"")
|
||||||
),
|
.to_string(),
|
||||||
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
let expanded_path = match std::process::Command::new("sh")
|
let expanded_path = match std::process::Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(format!("echo \"{}\"", p.to_string_lossy().replace("\"", "\\\"")))
|
.arg(format!("echo \"{}\"", p.to_string_lossy().replace("\"", "\\\"")))
|
||||||
.output() {
|
.output()
|
||||||
Ok(output) if output.status.success() => Some(String::from_utf8_lossy(&output.stdout).trim_end().to_string()),
|
{
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
Some(String::from_utf8_lossy(&output.stdout).trim_end().to_string())
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -168,12 +173,11 @@ pub fn optional_bool(s: &str) -> Option<bool> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{borrow::Cow, path::Path, env};
|
use std::{borrow::Cow, env, path::Path};
|
||||||
|
|
||||||
|
use super::path_relative_to;
|
||||||
use crate::expand_path;
|
use crate::expand_path;
|
||||||
|
|
||||||
use super::path_relative_to;
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_path_relative_to() {
|
fn test_path_relative_to() {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue