This commit is contained in:
PegasusPlusUS 2024-12-08 07:15:56 -08:00
parent 9078c182e8
commit 61594d9b16
5 changed files with 26 additions and 11 deletions

View file

@ -5,9 +5,11 @@ use nu_engine::env_to_string;
use nu_path::dots::expand_ndots;
use nu_path::{expand_to_real_path, home_dir};
use nu_protocol::{
engine::{expand_pwd, EngineState, Stack, StateWorkingSet},
engine::{EngineState, Stack, StateWorkingSet},
Span,
};
#[cfg(windows)]
use nu_protocol::engine::expand_pwd;
use nu_utils::get_ls_colors;
use nu_utils::IgnoreCaseExt;
use std::path::{is_separator, Component, Path, PathBuf, MAIN_SEPARATOR as SEP};

View file

@ -788,12 +788,17 @@ enum ReplOperation {
}
fn is_dir(path: &Path) -> bool {
if cfg!(not(windows)) {
#[cfg(not(windows))]
{
path.is_dir()
} else if let Some(path_str) = path.to_str() {
DRIVE_PATH_REGEX.is_match(path_str).unwrap_or(false) || path.is_dir()
} else {
false
}
#[cfg(windows)]
{
if let Some(path_str) = path.to_str() {
DRIVE_PATH_REGEX.is_match(path_str).unwrap_or(false) || path.is_dir()
} else {
false
}
}
}

View file

@ -29,7 +29,9 @@ pub use engine_state::*;
pub use error_handler::*;
pub use overlay::*;
pub use pattern_match::*;
pub use pwd_per_drive_helper::{expand_path_with, expand_pwd, set_pwd};
#[cfg(windows)]
pub use pwd_per_drive_helper::{expand_pwd, set_pwd};
pub use pwd_per_drive_helper::expand_path_with;
pub use sequence::*;
pub use stack::*;
pub use stack_out_dest::*;

View file

@ -2,12 +2,14 @@ use crate::{
engine::{EngineState, Stack},
Span, Value,
};
#[cfg(windows)]
use nu_path::{
bash_strip_redundant_quotes, ensure_trailing_delimiter, env_var_for_drive,
extract_drive_letter, get_full_path_name_w, need_expand,
};
use std::path::{Path, PathBuf};
#[cfg(windows)]
pub fn set_pwd(stack: &mut Stack, path: &Path) {
if let Some(drive) = extract_drive_letter(path) {
let value = Value::string(path.to_string_lossy(), Span::unknown());
@ -19,6 +21,7 @@ pub fn set_pwd(stack: &mut Stack, path: &Path) {
// 1. From env_var, if no,
// 2. From sys_absolute, if no,
// 3. Construct root path to drives
#[cfg(windows)]
fn get_pwd_on_drive(stack: &Stack, engine_state: &EngineState, drive_letter: char) -> String {
let env_var_for_drive = env_var_for_drive(drive_letter);
let mut abs_pwd: Option<String> = None;
@ -64,8 +67,8 @@ pub fn expand_pwd(stack: &Stack, engine_state: &EngineState, path: &Path) -> Opt
// Helper stub/proxy for nu_path::expand_path_with::<P, Q>(path, relative_to, expand_tilde)
// Facilitates file system commands to easily gain the ability to expand PWD-per-drive
pub fn expand_path_with<P, Q>(
stack: &Stack,
engine_state: &EngineState,
_stack: &Stack,
_engine_state: &EngineState,
path: P,
relative_to: Q,
expand_tilde: bool,
@ -75,13 +78,14 @@ where
Q: AsRef<Path>,
{
#[cfg(windows)]
if let Some(abs_path) = expand_pwd(stack, engine_state, path.as_ref()) {
if let Some(abs_path) = expand_pwd(_stack, _engine_state, path.as_ref()) {
return abs_path;
}
nu_path::expand_path_with::<P, Q>(path, relative_to, expand_tilde)
}
#[cfg(windows)]
#[cfg(test)]
mod tests {
use super::*;

View file

@ -1,10 +1,12 @@
use crate::{
engine::{
set_pwd, ArgumentStack, EngineState, ErrorHandlerStack, Redirection, StackCallArgGuard,
ArgumentStack, EngineState, ErrorHandlerStack, Redirection, StackCallArgGuard,
StackCollectValueGuard, StackIoGuard, StackOutDest, DEFAULT_OVERLAY_NAME,
},
Config, IntoValue, OutDest, ShellError, Span, Value, VarId, ENV_VARIABLE_ID, NU_VARIABLE_ID,
};
#[cfg(windows)]
use crate::engine::set_pwd;
use nu_utils::IgnoreCaseExt;
use std::{
collections::{HashMap, HashSet},