mirror of
https://github.com/nushell/nushell.git
synced 2024-12-03 22:06:54 +01:00
pub use to simplify usage
This commit is contained in:
parent
5dafde462a
commit
14b6da359a
@ -858,8 +858,7 @@ fn do_auto_cd(
|
|||||||
report_shell_error(engine_state, &err);
|
report_shell_error(engine_state, &err);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
use nu_path::pwd_per_drive::pwd_per_drive_singleton::set_pwd_per_drive;
|
let _ = nu_path::set_pwd_per_drive(PathBuf::from(path.clone()).as_path());
|
||||||
let _as_is = set_pwd_per_drive(PathBuf::from(path.clone()).as_path());
|
|
||||||
let cwd = Value::string(cwd, span);
|
let cwd = Value::string(cwd, span);
|
||||||
|
|
||||||
let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS");
|
let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS");
|
||||||
|
@ -114,8 +114,7 @@ impl Command for Cd {
|
|||||||
//FIXME: this only changes the current scope, but instead this environment variable
|
//FIXME: this only changes the current scope, but instead this environment variable
|
||||||
//should probably be a block that loads the information from the state in the overlay
|
//should probably be a block that loads the information from the state in the overlay
|
||||||
PermissionResult::PermissionOk => {
|
PermissionResult::PermissionOk => {
|
||||||
use nu_path::pwd_per_drive::pwd_per_drive_singleton::set_pwd_per_drive;
|
let _ = nu_path::set_pwd_per_drive(path.as_path());
|
||||||
let _as_is = set_pwd_per_drive(path.as_path());
|
|
||||||
stack.set_cwd(path)?;
|
stack.set_cwd(path)?;
|
||||||
Ok(PipelineData::empty())
|
Ok(PipelineData::empty())
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,6 @@ pub use components::components;
|
|||||||
pub use expansions::{canonicalize_with, expand_path_with, expand_to_real_path, locate_in_dirs};
|
pub use expansions::{canonicalize_with, expand_path_with, expand_to_real_path, locate_in_dirs};
|
||||||
pub use helpers::{cache_dir, data_dir, home_dir, nu_config_dir};
|
pub use helpers::{cache_dir, data_dir, home_dir, nu_config_dir};
|
||||||
pub use path::*;
|
pub use path::*;
|
||||||
|
pub use pwd_per_drive::pwd_per_drive_singleton::{set_pwd_per_drive, expand_pwd_per_drive};
|
||||||
pub use tilde::expand_tilde;
|
pub use tilde::expand_tilde;
|
||||||
pub use trailing_slash::{has_trailing_slash, strip_trailing_slash};
|
pub use trailing_slash::{has_trailing_slash, strip_trailing_slash};
|
||||||
|
@ -235,7 +235,7 @@ mod tests {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::path::{Path, PathBuf};
|
/// use std::path::{Path, PathBuf};
|
||||||
/// use nu_path::pwd_per_drive::pwd_per_drive_singleton::*;
|
/// use nu_path::{set_pwd_per_drive, expand_pwd_per_drive};
|
||||||
///
|
///
|
||||||
/// //assert!(false); // Comment out to verify really tested
|
/// //assert!(false); // Comment out to verify really tested
|
||||||
/// if cfg!(windows) {
|
/// if cfg!(windows) {
|
||||||
@ -323,10 +323,10 @@ pub mod pwd_per_drive_singleton {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_usage_for_pwd_per_drive() {
|
fn test_usage_for_pwd_per_drive() {
|
||||||
if cfg!(windows) {
|
|
||||||
// Set PWD for drive C
|
// Set PWD for drive C
|
||||||
set_pwd_per_drive(Path::new("C:\\Users\\Home")).unwrap();
|
assert_eq!(Ok(()), set_pwd_per_drive(Path::new("C:\\Users\\Home")));
|
||||||
|
|
||||||
|
if cfg!(windows) {
|
||||||
// Expand a relative path
|
// Expand a relative path
|
||||||
let expanded = expand_pwd_per_drive(Path::new("C:test"));
|
let expanded = expand_pwd_per_drive(Path::new("C:test"));
|
||||||
assert_eq!(expanded, Some(PathBuf::from("C:\\Users\\Home\\test")));
|
assert_eq!(expanded, Some(PathBuf::from("C:\\Users\\Home\\test")));
|
||||||
@ -342,6 +342,9 @@ pub mod pwd_per_drive_singleton {
|
|||||||
// Expand with no PWD set for the drive
|
// Expand with no PWD set for the drive
|
||||||
let expanded = expand_pwd_per_drive(Path::new("D:test"));
|
let expanded = expand_pwd_per_drive(Path::new("D:test"));
|
||||||
assert_eq!(expanded, Some(PathBuf::from("D:\\test")));
|
assert_eq!(expanded, Some(PathBuf::from("D:\\test")));
|
||||||
|
} else {
|
||||||
|
// None always
|
||||||
|
assert_eq!(None, expand_pwd_per_drive(Path::new("C:test")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,7 @@ fn expand_tilde_with_home(path: impl AsRef<Path>, home: Option<PathBuf>) -> Path
|
|||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
|
|
||||||
if !path.starts_with("~") {
|
if !path.starts_with("~") {
|
||||||
use crate::pwd_per_drive::pwd_per_drive_singleton::expand_pwd_per_drive;
|
if let Some(expanded_dir) = crate::expand_pwd_per_drive(path) {
|
||||||
if let Some(expanded_dir) = expand_pwd_per_drive(path) {
|
|
||||||
return expanded_dir;
|
return expanded_dir;
|
||||||
}
|
}
|
||||||
let string = path.to_string_lossy();
|
let string = path.to_string_lossy();
|
||||||
|
Loading…
Reference in New Issue
Block a user