mirror of
https://github.com/nushell/nushell.git
synced 2025-05-30 22:57:07 +02:00
remove the enter
, g
, n
, p
and shells
commands
This commit is contained in:
parent
a52386e837
commit
aea3598025
@ -1,103 +0,0 @@
|
||||
use super::{get_current_shell, get_shells};
|
||||
use nu_engine::{current_dir, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
pub struct Enter;
|
||||
|
||||
impl Command for Enter {
|
||||
fn name(&self) -> &str {
|
||||
"enter"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("enter")
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
.required(
|
||||
"path",
|
||||
SyntaxShape::Filepath,
|
||||
"the path to enter as a new shell",
|
||||
)
|
||||
.category(Category::Shells)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Enters a new shell at the given path."
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let new_path: Value = call.req(engine_state, stack, 0)?;
|
||||
let path_span = new_path.span()?;
|
||||
|
||||
let new_path = new_path.as_path()?;
|
||||
|
||||
let cwd = current_dir(engine_state, stack)?;
|
||||
let new_path = nu_path::canonicalize_with(new_path, &cwd)?;
|
||||
|
||||
if !new_path.exists() {
|
||||
return Err(ShellError::DirectoryNotFound(path_span, None));
|
||||
}
|
||||
|
||||
if !new_path.is_dir() {
|
||||
return Err(ShellError::DirectoryNotFoundCustom(
|
||||
"not a directory".to_string(),
|
||||
path_span,
|
||||
));
|
||||
}
|
||||
|
||||
let new_path = Value::string(new_path.to_string_lossy(), call.head);
|
||||
|
||||
let cwd = Value::string(cwd.to_string_lossy(), call.head);
|
||||
|
||||
let mut shells = get_shells(engine_state, stack, cwd);
|
||||
let mut current_shell = get_current_shell(engine_state, stack);
|
||||
|
||||
stack.add_env_var(
|
||||
"NUSHELL_LAST_SHELL".into(),
|
||||
Value::int(current_shell as i64, call.head),
|
||||
);
|
||||
|
||||
if current_shell + 1 > shells.len() {
|
||||
shells.push(new_path.clone());
|
||||
current_shell = shells.len();
|
||||
} else {
|
||||
shells.insert(current_shell + 1, new_path.clone());
|
||||
current_shell += 1;
|
||||
}
|
||||
|
||||
stack.add_env_var(
|
||||
"NUSHELL_SHELLS".into(),
|
||||
Value::List {
|
||||
vals: shells,
|
||||
span: call.head,
|
||||
},
|
||||
);
|
||||
stack.add_env_var(
|
||||
"NUSHELL_CURRENT_SHELL".into(),
|
||||
Value::int(current_shell as i64, call.head),
|
||||
);
|
||||
|
||||
stack.add_env_var("PWD".into(), new_path);
|
||||
|
||||
Ok(PipelineData::empty())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Enter a new shell at path '../dir-foo'",
|
||||
example: r#"enter ../dir-foo"#,
|
||||
result: None,
|
||||
}]
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
use super::{list_shells, switch_shell, SwitchTo};
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Type,
|
||||
};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
pub struct GotoShell;
|
||||
|
||||
impl Command for GotoShell {
|
||||
fn name(&self) -> &str {
|
||||
"g"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("g")
|
||||
.input_output_types(vec![
|
||||
(Type::Nothing, Type::Nothing),
|
||||
(Type::Nothing, Type::Table(vec![])),
|
||||
])
|
||||
.optional(
|
||||
"shell_number",
|
||||
SyntaxShape::String,
|
||||
"shell number to change to",
|
||||
)
|
||||
.category(Category::Shells)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Switch to a given shell, or list all shells if no given shell number."
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let new_shell: Option<Spanned<String>> = call.opt(engine_state, stack, 0)?;
|
||||
|
||||
match new_shell {
|
||||
Some(shell_span) => {
|
||||
if shell_span.item == "-" {
|
||||
switch_shell(engine_state, stack, call, shell_span.span, SwitchTo::Last)
|
||||
} else {
|
||||
let n = shell_span
|
||||
.item
|
||||
.parse::<usize>()
|
||||
.map_err(|_| ShellError::NotFound {
|
||||
span: shell_span.span,
|
||||
})?;
|
||||
|
||||
switch_shell(engine_state, stack, call, shell_span.span, SwitchTo::Nth(n))
|
||||
}
|
||||
}
|
||||
None => list_shells(engine_state, stack, call.head),
|
||||
}
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Lists all open shells",
|
||||
example: r#"g"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Make two directories and enter new shells for them, use `g` to jump to the specific shell",
|
||||
example: r#"mkdir foo bar; enter foo; enter ../bar; g 1"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Use `shells` to show all the opened shells and run `g 2` to jump to the third one",
|
||||
example: r#"shells; g 2"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Make two directories and enter new shells for them, use `g -` to jump to the last used shell",
|
||||
example: r#"mkdir foo bar; enter foo; enter ../bar; g -"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use super::{switch_shell, SwitchTo};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
pub struct NextShell;
|
||||
|
||||
impl Command for NextShell {
|
||||
fn name(&self) -> &str {
|
||||
"n"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("n")
|
||||
.category(Category::Shells)
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Switch to the next shell."
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
switch_shell(engine_state, stack, call, call.head, SwitchTo::Next)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Make two directories and enter new shells for them, use `n` to jump to the next shell",
|
||||
example: r#"mkdir foo bar; enter foo; enter ../bar; n"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Run `n` several times and note the changes of current directory",
|
||||
example: r#"n"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use super::{switch_shell, SwitchTo};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
pub struct PrevShell;
|
||||
|
||||
impl Command for PrevShell {
|
||||
fn name(&self) -> &str {
|
||||
"p"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("p")
|
||||
.category(Category::Shells)
|
||||
.input_output_types(vec![(Type::Nothing, Type::Nothing)])
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Switch to the previous shell."
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
switch_shell(engine_state, stack, call, call.head, SwitchTo::Prev)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Make two directories and enter new shells for them, use `p` to jump to the previous shell",
|
||||
example: r#"mkdir foo bar; enter foo; enter ../bar; p"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Run `p` several times and note the changes of current directory",
|
||||
example: r#"p"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use super::list_shells;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, Type};
|
||||
|
||||
/// Source a file for environment variables.
|
||||
#[derive(Clone)]
|
||||
pub struct Shells;
|
||||
|
||||
impl Command for Shells {
|
||||
fn name(&self) -> &str {
|
||||
"shells"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("shells")
|
||||
.category(Category::Shells)
|
||||
.input_output_types(vec![(Type::Nothing, Type::Table(vec![]))])
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Lists all open shells."
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
list_shells(engine_state, stack, call.head)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Enter a new shell at parent path '..' and show all opened shells",
|
||||
example: r#"enter ..; shells"#,
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Show currently active shell",
|
||||
example: r#"shells | where active == true"#,
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user