Skip to content

Commit d9d604d

Browse files
committed
fix: 🐛 Ensure code is working with nu 0.99.0 again
1 parent 8717fe1 commit d9d604d

File tree

6 files changed

+28
-9
lines changed

6 files changed

+28
-9
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ nu-utils = "0.99.0"
2727
thiserror = "1.0.59"
2828
miette = { version = "7.2", features = ["fancy-no-backtrace", "fancy"] }
2929
nu-ansi-term = "0.50.1"
30+
nu-path = "0.99.0"
3031

3132
[target.'cfg(not(target_os = "windows"))'.dependencies]
3233
openssl = { version = "0.10", features = ["vendored"], optional = true }

src/engine.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::errors::{NurError, NurResult};
44
use crate::names::{
55
NUR_ENV_NUR_TASK_CALL, NUR_ENV_NUR_TASK_NAME, NUR_ENV_NUR_VERSION, NUR_ENV_NU_LIB_DIRS,
66
NUR_NAME, NUR_VAR_CONFIG_DIR, NUR_VAR_DEFAULT_LIB_DIR, NUR_VAR_PROJECT_PATH, NUR_VAR_RUN_PATH,
7-
NUR_VAR_TASK_NAME, NUSHELL_FOLDER,
7+
NUR_VAR_TASK_NAME,
88
};
99
use crate::nu_version::NU_VERSION;
1010
use crate::scripts::{get_default_nur_config, get_default_nur_env};
@@ -312,8 +312,8 @@ impl NurEngine {
312312
// Merge env is requested
313313
if merge_env {
314314
match self.engine_state.cwd(Some(&self.stack)) {
315-
Ok(cwd) => {
316-
if let Err(e) = self.engine_state.merge_env(&mut self.stack, cwd) {
315+
Ok(_cwd) => {
316+
if let Err(e) = self.engine_state.merge_env(&mut self.stack) {
317317
report_shell_error(&self.engine_state, &e);
318318
}
319319
}
@@ -412,7 +412,6 @@ impl NurEngine {
412412
match evaluate_repl(
413413
&mut self.engine_state,
414414
self.stack.clone(),
415-
NUSHELL_FOLDER,
416415
None,
417416
None,
418417
std::time::Instant::now(),

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ use crate::compat::show_nurscripts_hint;
1414
use crate::engine::init_engine_state;
1515
use crate::engine::NurEngine;
1616
use crate::errors::NurError;
17+
use crate::path::current_dir_from_environment;
1718
use crate::state::NurState;
1819
use miette::Result;
1920
use nu_ansi_term::Color;
20-
use nu_cmd_base::util::get_init_cwd;
2121
use nu_protocol::{ByteStream, PipelineData, Span};
2222
use std::env;
2323
use std::process::ExitCode;
2424

2525
fn main() -> Result<ExitCode, miette::ErrReport> {
2626
// Initialise nur state
27-
let run_path = get_init_cwd().into_std_path_buf();
27+
let run_path = current_dir_from_environment();
2828
let nur_state = NurState::new(run_path, env::args().collect())?;
2929

3030
// Create raw nu engine state

src/names.rs

-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,3 @@ pub(crate) const NUR_VAR_DEFAULT_LIB_DIR: &str = "default-lib-dir";
2222
// nurfile names
2323
pub(crate) const NUR_FILE: &str = "nurfile";
2424
pub(crate) const NUR_LOCAL_FILE: &str = "nurfile.local";
25-
26-
// nu shell consts
27-
pub(crate) const NUSHELL_FOLDER: &str = "nushell"; // nu-cli -> config_files.rs, used for REPL

src/path.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
use crate::names::NUR_FILE;
22
use std::path::{Path, PathBuf};
33

4+
/// Get the directory where the Nushell executable is located.
5+
fn current_exe_directory() -> PathBuf {
6+
let mut path = std::env::current_exe().expect("current_exe() should succeed");
7+
path.pop();
8+
path
9+
}
10+
11+
/// Get the current working directory from the environment.
12+
pub(crate) fn current_dir_from_environment() -> PathBuf {
13+
if let Ok(cwd) = std::env::current_dir() {
14+
return cwd;
15+
}
16+
if let Ok(cwd) = std::env::var("PWD") {
17+
return cwd.into();
18+
}
19+
if let Some(home) = nu_path::home_dir() {
20+
return home.into_std_path_buf();
21+
}
22+
current_exe_directory()
23+
}
24+
425
pub(crate) fn find_project_path<P: AsRef<Path>>(cwd: P) -> Option<PathBuf> {
526
let mut path = cwd.as_ref();
627

0 commit comments

Comments
 (0)