forked from extern/nushell
export get_shells
and get_current_shell
(#6236)
Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
parent
cc99df5ef1
commit
692376e830
@ -1,4 +1,5 @@
|
||||
use crate::filesystem::cd_query::query;
|
||||
use crate::{get_current_shell, get_shells};
|
||||
use nu_engine::{current_dir, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
@ -146,22 +147,8 @@ impl Command for Cd {
|
||||
span: call.head,
|
||||
};
|
||||
|
||||
let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS");
|
||||
let mut shells = if let Some(v) = shells {
|
||||
v.as_list()
|
||||
.map(|x| x.to_vec())
|
||||
.unwrap_or_else(|_| vec![cwd])
|
||||
} else {
|
||||
vec![cwd]
|
||||
};
|
||||
|
||||
let current_shell = stack.get_env_var(engine_state, "NUSHELL_CURRENT_SHELL");
|
||||
let current_shell = if let Some(v) = current_shell {
|
||||
v.as_integer().unwrap_or_default() as usize
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let mut shells = get_shells(engine_state, stack, cwd);
|
||||
let current_shell = get_current_shell(engine_state, stack);
|
||||
shells[current_shell] = path_value.clone();
|
||||
|
||||
stack.add_env_var(
|
||||
|
@ -14,7 +14,7 @@ use nu_protocol::Value;
|
||||
pub use p::PrevShell;
|
||||
pub use shells_::Shells;
|
||||
|
||||
fn get_shells(engine_state: &EngineState, stack: &mut Stack, cwd: Value) -> Vec<Value> {
|
||||
pub fn get_shells(engine_state: &EngineState, stack: &mut Stack, cwd: Value) -> Vec<Value> {
|
||||
let shells = stack.get_env_var(engine_state, "NUSHELL_SHELLS");
|
||||
let shells = if let Some(v) = shells {
|
||||
v.as_list()
|
||||
@ -26,7 +26,7 @@ fn get_shells(engine_state: &EngineState, stack: &mut Stack, cwd: Value) -> Vec<
|
||||
shells
|
||||
}
|
||||
|
||||
fn get_current_shell(engine_state: &EngineState, stack: &mut Stack) -> usize {
|
||||
pub fn get_current_shell(engine_state: &EngineState, stack: &mut Stack) -> usize {
|
||||
let current_shell = stack.get_env_var(engine_state, "NUSHELL_CURRENT_SHELL");
|
||||
if let Some(v) = current_shell {
|
||||
v.as_integer().unwrap_or_default() as usize
|
||||
|
Loading…
Reference in New Issue
Block a user