Add --no-newline option to nu (#12410)

# Description
I have `nu` set as my shell in my editor, which allows me to easily pipe
selections of text to things like `str pascal-case` or even more complex
string operation pipelines, which I find super handy. However, the only
annoying thing is that I pretty much always have to add `| print -n` at
the end, because `nu` adds a newline when it prints the resulting value.

This adds a `--no-newline` option to stop that from happening, and then
you don't need to pipe to `print -n` anymore, you can just have your
shell command for your editor contain that flag.

# User-Facing Changes
- Add `--no-newline` command line option

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
This commit is contained in:
Devyn Cairns
2024-04-09 07:04:00 -07:00
committed by GitHub
parent 00b3a07efe
commit 14b0ff3f05
6 changed files with 41 additions and 6 deletions

View File

@ -97,6 +97,7 @@ pub(crate) fn parse_commandline_args(
let execute = call.get_flag_expr("execute");
let table_mode: Option<Value> =
call.get_flag(engine_state, &mut stack, "table-mode")?;
let no_newline = call.get_named_arg("no-newline");
// ide flags
let lsp = call.has_flag(engine_state, &mut stack, "lsp")?;
@ -190,6 +191,7 @@ pub(crate) fn parse_commandline_args(
ide_check,
ide_ast,
table_mode,
no_newline,
});
}
}
@ -224,6 +226,7 @@ pub(crate) struct NushellCliArgs {
pub(crate) log_target: Option<Spanned<String>>,
pub(crate) execute: Option<Spanned<String>>,
pub(crate) table_mode: Option<Value>,
pub(crate) no_newline: Option<Spanned<String>>,
pub(crate) include_path: Option<Spanned<String>>,
pub(crate) lsp: bool,
pub(crate) ide_goto_def: Option<Value>,
@ -270,6 +273,7 @@ impl Command for Nu {
"the table mode to use. rounded is default.",
Some('m'),
)
.switch("no-newline", "print the result for --commands(-c) without a newline", None)
.switch(
"no-config-file",
"start with no config file and no env file",

View File

@ -118,6 +118,7 @@ pub(crate) fn run_commands(
&mut stack,
input,
parsed_nu_cli_args.table_mode,
parsed_nu_cli_args.no_newline.is_some(),
);
perf(
"evaluate_commands",