Fix editor config for reedline and config nu/env (#10535)

# Description
This merges @horasal 's changes from #10246 and #10269

Closes #10205
Closes #8714

Fixes the bug that editor paths with spaces are unusable

Closes #10210 
Closes #10269


# User-Facing Changes
You can now either pass a string with the name of the executable or a
list with the executable and any flags to
`$env.config.buffer_editor`/`$env.EDITOR`/`$env.VISUAL`

Both the external buffer editor of reedline (by default bound to
`Ctrl-o`) and the commands `config nu` and `config env` will respect
those variables in the following order:
1. `$env.config.buffer_editor`
2. `$env.EDITOR`
3. `$env.VISUAL`

Example:
```
$env.EDITOR = "nvim"                      # The system-wide EDITOR is neovim
$env.config.buffer_editor = ["vim" "-p2"] # Force vim to open two tabs (not particularly useful)
$env.config.buffer_editor = null          # Unset `buffer_editor` -> Uses `$env.EDITOR` ergo nvim
```
# Tests + Formatting
None

---------

Co-authored-by: Horasal <1991933+horasal@users.noreply.github.com>
This commit is contained in:
Stefan Holderbach
2023-09-29 16:36:03 +02:00
committed by GitHub
parent f2af12af2c
commit 80a183dde2
9 changed files with 108 additions and 71 deletions

View File

@ -98,7 +98,7 @@ pub struct Config {
pub hooks: Hooks,
pub rm_always_trash: bool,
pub shell_integration: bool,
pub buffer_editor: String,
pub buffer_editor: Value,
pub table_index_mode: TableIndexMode,
pub cd_with_abbreviations: bool,
pub case_sensitive_completions: bool,
@ -167,7 +167,7 @@ impl Default for Config {
use_grid_icons: true,
footer_mode: FooterMode::RowCount(25),
float_precision: 2,
buffer_editor: String::new(),
buffer_editor: Value::nothing(Span::unknown()),
use_ansi_coloring: true,
bracketed_paste: true,
edit_mode: "emacs".into(),
@ -1187,13 +1187,20 @@ impl Value {
"shell_integration" => {
try_bool!(cols, vals, index, span, shell_integration);
}
"buffer_editor" => {
if let Ok(v) = value.as_string() {
config.buffer_editor = v.to_lowercase();
} else {
invalid!(Some(span), "should be a string");
"buffer_editor" => match value {
Value::Nothing { .. } | Value::String { .. } => {
config.buffer_editor = value.clone();
}
}
Value::List { vals, .. }
if vals.iter().all(|val| matches!(val, Value::String { .. })) =>
{
config.buffer_editor = value.clone();
}
_ => {
dbg!(value);
invalid!(Some(span), "should be a string, list<string>, or null");
}
},
"show_banner" => {
try_bool!(cols, vals, index, span, show_banner);
}