Skip to content

Commit

Permalink
Allows cwd to be set to None
Browse files Browse the repository at this point in the history
  • Loading branch information
YizhePKU committed Jul 3, 2024
1 parent 19d8c5d commit fdd5716
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ pub struct Reedline {
// Use ansi coloring or not
use_ansi_coloring: bool,

// Current working directory as defined by the application, which might not
// be the actual working directory of the process
cwd: String,
// Current working directory as defined by the application. If set, it will
// override the actual working directory of the process.
cwd: Option<String>,

// Engine Menus
menus: Vec<ReedlineMenu>,
Expand Down Expand Up @@ -228,7 +228,7 @@ impl Reedline {
hide_hints: false,
validator,
use_ansi_coloring: true,
cwd: "".to_string(),
cwd: None,
menus: Vec::new(),
buffer_editor: None,
cursor_shapes: None,
Expand Down Expand Up @@ -367,7 +367,7 @@ impl Reedline {

/// Update current working directory.
#[must_use]
pub fn with_cwd(mut self, cwd: String) -> Self {
pub fn with_cwd(mut self, cwd: Option<String>) -> Self {
self.cwd = cwd;
self
}
Expand Down Expand Up @@ -1569,7 +1569,12 @@ impl Reedline {
.history
.search(SearchQuery::last_with_prefix_and_cwd(
parsed.prefix.unwrap().to_string(),
self.cwd.clone(),
self.cwd.clone().unwrap_or_else(|| {
std::env::current_dir()
.unwrap_or_default()
.to_string_lossy()
.to_string()
}),
self.get_history_session_id(),
))
.unwrap_or_else(|_| Vec::new())
Expand Down Expand Up @@ -1752,7 +1757,12 @@ impl Reedline {
cursor_position_in_buffer,
self.history.as_ref(),
self.use_ansi_coloring,
&self.cwd,
&self.cwd.clone().unwrap_or_else(|| {
std::env::current_dir()
.unwrap_or_default()
.to_string_lossy()
.to_string()
}),
)
})
} else {
Expand Down

0 comments on commit fdd5716

Please sign in to comment.