mirror of
https://github.com/nushell/nushell.git
synced 2025-04-30 08:04:25 +02:00
* Grouped config commands better * Tweaked test slightly * Fix merge conflict(?) * Remove recently-added test case * Revert rm.always_trash default * Untweak rm help messages * Formatting * Remove example * Add deprecation warning * Remove deprecation timeline Not sure we want to commit to a specific timeline just yet Co-authored-by: Reilly Wood <26268125+rgwood@users.noreply.github.com>
This commit is contained in:
parent
4b83a2d27a
commit
7479173811
@ -88,12 +88,12 @@ impl Command for Rm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn examples(&self) -> Vec<Example> {
|
fn examples(&self) -> Vec<Example> {
|
||||||
let mut examples = vec![
|
let mut examples = vec![Example {
|
||||||
Example {
|
description:
|
||||||
description: "Delete or move a file to the system trash (depending on 'rm_always_trash' config option)",
|
"Delete or move a file to the trash (depending on 'always_trash' config option)",
|
||||||
example: "rm file.txt",
|
example: "rm file.txt",
|
||||||
result: None,
|
result: None,
|
||||||
}];
|
}];
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
feature = "trash-support",
|
feature = "trash-support",
|
||||||
not(target_os = "android"),
|
not(target_os = "android"),
|
||||||
@ -164,7 +164,7 @@ fn rm(
|
|||||||
if rm_always_trash {
|
if rm_always_trash {
|
||||||
return Err(ShellError::GenericError(
|
return Err(ShellError::GenericError(
|
||||||
"Cannot execute `rm`; the current configuration specifies \
|
"Cannot execute `rm`; the current configuration specifies \
|
||||||
`rm_always_trash = true`, but the current nu executable was not \
|
`always_trash = true`, but the current nu executable was not \
|
||||||
built with feature `trash_support` or trash is not supported on \
|
built with feature `trash_support` or trash is not supported on \
|
||||||
your platform."
|
your platform."
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -189,35 +189,337 @@ impl Value {
|
|||||||
|
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
|
|
||||||
|
let mut legacy_options_used = false;
|
||||||
|
|
||||||
if let Ok(v) = v {
|
if let Ok(v) = v {
|
||||||
for (key, value) in v.0.iter().zip(v.1) {
|
for (key, value) in v.0.iter().zip(v.1) {
|
||||||
match key.as_str() {
|
let key = key.as_str();
|
||||||
"filesize_metric" => {
|
match key {
|
||||||
if let Ok(b) = value.as_bool() {
|
// Grouped options
|
||||||
config.filesize_metric = b;
|
"ls" => {
|
||||||
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key2 = key2.as_str();
|
||||||
|
match key2 {
|
||||||
|
"use_ls_colors" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.use_ls_colors = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"clickable_links" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.show_clickable_links_in_ls = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.filesize_metric is not a bool")
|
eprintln!("$env.config.{} is not a record", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"external_completer" => {
|
"cd" => {
|
||||||
if let Ok(v) = value.as_block() {
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
config.external_completer = Some(v)
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
}
|
let key2 = key2.as_str();
|
||||||
}
|
match key2 {
|
||||||
"table_mode" => {
|
"abbreviations" => {
|
||||||
if let Ok(v) = value.as_string() {
|
if let Ok(b) = value.as_bool() {
|
||||||
config.table_mode = v;
|
config.cd_with_abbreviations = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.table_mode is not a string")
|
eprintln!("$env.config.{} is not a record", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"use_ls_colors" => {
|
"rm" => {
|
||||||
if let Ok(b) = value.as_bool() {
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
config.use_ls_colors = b;
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key2 = key2.as_str();
|
||||||
|
match key2 {
|
||||||
|
"always_trash" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.rm_always_trash = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.use_ls_colors is not a bool")
|
eprintln!("$env.config.{} is not a record", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"history" => {
|
||||||
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key2 = key2.as_str();
|
||||||
|
match key2 {
|
||||||
|
"sync_on_enter" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.sync_history_on_enter = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"max_size" => {
|
||||||
|
if let Ok(i) = value.as_i64() {
|
||||||
|
config.max_history_size = i;
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not an integer",
|
||||||
|
key, key2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"file_format" => {
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
let val_str = v.to_lowercase();
|
||||||
|
config.history_file_format = match val_str.as_ref() {
|
||||||
|
"sqlite" => HistoryFileFormat::Sqlite,
|
||||||
|
"plaintext" => HistoryFileFormat::PlainText,
|
||||||
|
_ => {
|
||||||
|
eprintln!(
|
||||||
|
"unrecognized $config.{}.{} '{val_str}'; expected either 'sqlite' or 'plaintext'",
|
||||||
|
key, key2,
|
||||||
|
);
|
||||||
|
HistoryFileFormat::PlainText
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not a string",
|
||||||
|
key, key2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{} is not a record", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"completions" => {
|
||||||
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key2 = key2.as_str();
|
||||||
|
match key2 {
|
||||||
|
"quick" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.quick_completions = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"partial" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.partial_completions = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"algorithm" => {
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
let val_str = v.to_lowercase();
|
||||||
|
config.completion_algorithm = match val_str.as_ref() {
|
||||||
|
// This should match the MatchAlgorithm enum in completions::completion_options
|
||||||
|
"prefix" => val_str,
|
||||||
|
"fuzzy" => val_str,
|
||||||
|
_ => {
|
||||||
|
eprintln!(
|
||||||
|
"unrecognized $config.{}.{} '{val_str}'; expected either 'prefix' or 'fuzzy'",
|
||||||
|
key, key2
|
||||||
|
);
|
||||||
|
String::from("prefix")
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not a string",
|
||||||
|
key, key2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"case_sensitive" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.case_sensitive_completions = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"external" => {
|
||||||
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
|
for (key3, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key3 = key3.as_str();
|
||||||
|
match key3 {
|
||||||
|
"max_results" => {
|
||||||
|
if let Ok(i) = value.as_integer() {
|
||||||
|
config
|
||||||
|
.max_external_completion_results =
|
||||||
|
i;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{}.{} is not an integer", key, key2, key3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"completer" => {
|
||||||
|
if let Ok(v) = value.as_block() {
|
||||||
|
config.external_completer = Some(v)
|
||||||
|
} else {
|
||||||
|
match value {
|
||||||
|
Value::Nothing { .. } => {}
|
||||||
|
_ => {
|
||||||
|
eprintln!("$env.config.{}.{}.{} is not a block or null", key, key2, key3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"enable" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.enable_external_completion = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{}.{} is not a bool", key, key2, key3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!("$env.config.{}.{}.{} is an unknown config setting", key, key2, x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not a record",
|
||||||
|
key, key2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{} is not a record", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"table" => {
|
||||||
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key2 = key2.as_str();
|
||||||
|
match key2 {
|
||||||
|
"mode" => {
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
config.table_mode = v;
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not a string",
|
||||||
|
key, key2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"index_mode" => {
|
||||||
|
if let Ok(b) = value.as_string() {
|
||||||
|
let val_str = b.to_lowercase();
|
||||||
|
match val_str.as_ref() {
|
||||||
|
"always" => config.table_index_mode = TableIndexMode::Always,
|
||||||
|
"never" => config.table_index_mode = TableIndexMode::Never,
|
||||||
|
"auto" => config.table_index_mode = TableIndexMode::Auto,
|
||||||
|
_ => eprintln!(
|
||||||
|
"unrecognized $env.config.{}.{} '{val_str}'; expected either 'never', 'always' or 'auto'",
|
||||||
|
key, key2
|
||||||
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not a string",
|
||||||
|
key, key2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"trim" => {
|
||||||
|
config.trim_strategy =
|
||||||
|
try_parse_trim_strategy(value, &config)?
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{} is not a record", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"filesize" => {
|
||||||
|
if let Ok((cols, inner_vals)) = value.as_record() {
|
||||||
|
for (key2, value) in cols.iter().zip(inner_vals) {
|
||||||
|
let key2 = key2.as_str();
|
||||||
|
match key2 {
|
||||||
|
"metric" => {
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.filesize_metric = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{}.{} is not a bool", key, key2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"format" => {
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
config.filesize_format = v.to_lowercase();
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is not a string",
|
||||||
|
key, key2
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x => {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.{}.{} is an unknown config setting",
|
||||||
|
key, x
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.{} is not a record", key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Misc. options
|
||||||
"color_config" => {
|
"color_config" => {
|
||||||
if let Ok(map) = create_map(value, &config) {
|
if let Ok(map) = create_map(value, &config) {
|
||||||
config.color_config = map;
|
config.color_config = map;
|
||||||
@ -229,7 +531,7 @@ impl Value {
|
|||||||
if let Ok(b) = value.as_bool() {
|
if let Ok(b) = value.as_bool() {
|
||||||
config.use_grid_icons = b;
|
config.use_grid_icons = b;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.use_grid_icons is not a bool")
|
eprintln!("$env.config.{} is not a bool", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"footer_mode" => {
|
"footer_mode" => {
|
||||||
@ -245,128 +547,55 @@ impl Value {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.footer_mode is not a string")
|
eprintln!("$env.config.{} is not a string", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"float_precision" => {
|
"float_precision" => {
|
||||||
if let Ok(i) = value.as_integer() {
|
if let Ok(i) = value.as_integer() {
|
||||||
config.float_precision = i;
|
config.float_precision = i;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.float_precision is not an integer")
|
eprintln!("$env.config.{} is not an integer", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"use_ansi_coloring" => {
|
"use_ansi_coloring" => {
|
||||||
if let Ok(b) = value.as_bool() {
|
if let Ok(b) = value.as_bool() {
|
||||||
config.use_ansi_coloring = b;
|
config.use_ansi_coloring = b;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.use_ansi_coloring is not a bool")
|
eprintln!("$env.config.{} is not a bool", key)
|
||||||
}
|
|
||||||
}
|
|
||||||
"quick_completions" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.quick_completions = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.quick_completions is not a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"partial_completions" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.partial_completions = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.partial_completions is not a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"max_external_completion_results" => {
|
|
||||||
if let Ok(i) = value.as_integer() {
|
|
||||||
config.max_external_completion_results = i;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.max_external_completion_results is not an integer")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"completion_algorithm" => {
|
|
||||||
if let Ok(v) = value.as_string() {
|
|
||||||
config.completion_algorithm = v.to_lowercase();
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.completion_algorithm is not a string")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"rm_always_trash" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.rm_always_trash = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.rm_always_trash is not a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"filesize_format" => {
|
|
||||||
if let Ok(v) = value.as_string() {
|
|
||||||
config.filesize_format = v.to_lowercase();
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.filesize_format is not a string")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"edit_mode" => {
|
"edit_mode" => {
|
||||||
if let Ok(v) = value.as_string() {
|
if let Ok(v) = value.as_string() {
|
||||||
config.edit_mode = v.to_lowercase();
|
config.edit_mode = v.to_lowercase();
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.edit_mode is not a string")
|
eprintln!("$env.config.{} is not a string", key)
|
||||||
}
|
|
||||||
}
|
|
||||||
"history_file_format" => {
|
|
||||||
if let Ok(b) = value.as_string() {
|
|
||||||
let val_str = b.to_lowercase();
|
|
||||||
config.history_file_format = match val_str.as_ref() {
|
|
||||||
"sqlite" => HistoryFileFormat::Sqlite,
|
|
||||||
"plaintext" => HistoryFileFormat::PlainText,
|
|
||||||
_ => {
|
|
||||||
eprintln!(
|
|
||||||
"unrecognized $config.history_file_format '{val_str}'"
|
|
||||||
);
|
|
||||||
HistoryFileFormat::PlainText
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.history_file_format is not a string")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"max_history_size" => {
|
|
||||||
if let Ok(i) = value.as_i64() {
|
|
||||||
config.max_history_size = i;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.max_history_size is not an integer")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"sync_history_on_enter" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.sync_history_on_enter = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.sync_history_on_enter is not a bool")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"log_level" => {
|
"log_level" => {
|
||||||
if let Ok(v) = value.as_string() {
|
if let Ok(v) = value.as_string() {
|
||||||
config.log_level = v.to_lowercase();
|
config.log_level = v.to_lowercase();
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.log_level is not a string")
|
eprintln!("$env.config.{} is not a string", key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"menus" => match create_menus(value) {
|
"menus" => match create_menus(value) {
|
||||||
Ok(map) => config.menus = map,
|
Ok(map) => config.menus = map,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("$config.menus is not a valid list of menus");
|
eprintln!("$env.config.{} is not a valid list of menus", key);
|
||||||
eprintln!("{:?}", e);
|
eprintln!("{:?}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"keybindings" => match create_keybindings(value) {
|
"keybindings" => match create_keybindings(value) {
|
||||||
Ok(keybindings) => config.keybindings = keybindings,
|
Ok(keybindings) => config.keybindings = keybindings,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("$config.keybindings is not a valid keybindings list");
|
eprintln!("$env.config.{} is not a valid keybindings list", key);
|
||||||
eprintln!("{:?}", e);
|
eprintln!("{:?}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hooks" => match create_hooks(value) {
|
"hooks" => match create_hooks(value) {
|
||||||
Ok(hooks) => config.hooks = hooks,
|
Ok(hooks) => config.hooks = hooks,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("$config.hooks is not a valid hooks list");
|
eprintln!("$env.config.{} is not a valid hooks list", key);
|
||||||
eprintln!("{:?}", e);
|
eprintln!("{:?}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -374,76 +603,196 @@ impl Value {
|
|||||||
if let Ok(b) = value.as_bool() {
|
if let Ok(b) = value.as_bool() {
|
||||||
config.shell_integration = b;
|
config.shell_integration = b;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.shell_integration is not a bool")
|
eprintln!("$env.config.{} is not a bool", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"buffer_editor" => {
|
"buffer_editor" => {
|
||||||
if let Ok(v) = value.as_string() {
|
if let Ok(v) = value.as_string() {
|
||||||
config.buffer_editor = v.to_lowercase();
|
config.buffer_editor = v.to_lowercase();
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.buffer_editor is not a string")
|
eprintln!("$env.config.{} is not a string", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"table_index_mode" => {
|
|
||||||
if let Ok(b) = value.as_string() {
|
|
||||||
let val_str = b.to_lowercase();
|
|
||||||
match val_str.as_ref() {
|
|
||||||
"always" => config.table_index_mode = TableIndexMode::Always,
|
|
||||||
"never" => config.table_index_mode = TableIndexMode::Never,
|
|
||||||
"auto" => config.table_index_mode = TableIndexMode::Auto,
|
|
||||||
_ => eprintln!(
|
|
||||||
"$config.table_index_mode must be a never, always or auto"
|
|
||||||
),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.table_index_mode is not a string")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"cd_with_abbreviations" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.cd_with_abbreviations = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.cd_with_abbreviations is not a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"case_sensitive_completions" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.case_sensitive_completions = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.case_sensitive_completions is not a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"enable_external_completion" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.enable_external_completion = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.enable_external_completion is not a bool")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"table_trim" => config.trim_strategy = try_parse_trim_strategy(value, &config)?,
|
|
||||||
"show_banner" => {
|
"show_banner" => {
|
||||||
if let Ok(b) = value.as_bool() {
|
if let Ok(b) = value.as_bool() {
|
||||||
config.show_banner = b;
|
config.show_banner = b;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.show_banner is not a bool")
|
eprintln!("$env.config.{} is not a bool", key);
|
||||||
}
|
|
||||||
}
|
|
||||||
"show_clickable_links_in_ls" => {
|
|
||||||
if let Ok(b) = value.as_bool() {
|
|
||||||
config.show_clickable_links_in_ls = b;
|
|
||||||
} else {
|
|
||||||
eprintln!("$config.show_clickable_links_in_ls is not a bool")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"render_right_prompt_on_last_line" => {
|
"render_right_prompt_on_last_line" => {
|
||||||
if let Ok(b) = value.as_bool() {
|
if let Ok(b) = value.as_bool() {
|
||||||
config.render_right_prompt_on_last_line = b;
|
config.render_right_prompt_on_last_line = b;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.render_right_prompt_on_last_line is not a bool")
|
eprintln!("$env.config.{} is not a bool", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Legacy config options (deprecated as of 2022-11-02)
|
||||||
|
"use_ls_colors" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.use_ls_colors = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.use_ls_colors is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"rm_always_trash" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.rm_always_trash = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.rm_always_trash is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"history_file_format" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_string() {
|
||||||
|
let val_str = b.to_lowercase();
|
||||||
|
config.history_file_format = match val_str.as_ref() {
|
||||||
|
"sqlite" => HistoryFileFormat::Sqlite,
|
||||||
|
"plaintext" => HistoryFileFormat::PlainText,
|
||||||
|
_ => {
|
||||||
|
eprintln!(
|
||||||
|
"unrecognized $env.config.history_file_format '{val_str}'"
|
||||||
|
);
|
||||||
|
HistoryFileFormat::PlainText
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.history_file_format is not a string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"sync_history_on_enter" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.sync_history_on_enter = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.sync_history_on_enter is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"max_history_size" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(i) = value.as_i64() {
|
||||||
|
config.max_history_size = i;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.max_history_size is not an integer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"quick_completions" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.quick_completions = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.quick_completions is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"partial_completions" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.partial_completions = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.partial_completions is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"max_external_completion_results" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(i) = value.as_integer() {
|
||||||
|
config.max_external_completion_results = i;
|
||||||
|
} else {
|
||||||
|
eprintln!(
|
||||||
|
"$env.config.max_external_completion_results is not an integer"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"completion_algorithm" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
let val_str = v.to_lowercase();
|
||||||
|
config.completion_algorithm = match val_str.as_ref() {
|
||||||
|
// This should match the MatchAlgorithm enum in completions::completion_options
|
||||||
|
"prefix" => val_str,
|
||||||
|
"fuzzy" => val_str,
|
||||||
|
_ => {
|
||||||
|
eprintln!(
|
||||||
|
"unrecognized $env.config.completions.algorithm '{val_str}'; expected either 'prefix' or 'fuzzy'"
|
||||||
|
);
|
||||||
|
val_str
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.completion_algorithm is not a string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"case_sensitive_completions" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.case_sensitive_completions = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.case_sensitive_completions is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"enable_external_completion" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.enable_external_completion = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.enable_external_completion is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"external_completer" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(v) = value.as_block() {
|
||||||
|
config.external_completer = Some(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"table_mode" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
config.table_mode = v;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.table_mode is not a string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"table_trim" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
config.trim_strategy = try_parse_trim_strategy(value, &config)?
|
||||||
|
}
|
||||||
|
"show_clickable_links_in_ls" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.show_clickable_links_in_ls = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.show_clickable_links_in_ls is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"cd_with_abbreviations" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.cd_with_abbreviations = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.cd_with_abbreviations is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"filesize_metric" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(b) = value.as_bool() {
|
||||||
|
config.filesize_metric = b;
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.filesize_metric is not a bool")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"filesize_format" => {
|
||||||
|
legacy_options_used = true;
|
||||||
|
if let Ok(v) = value.as_string() {
|
||||||
|
config.filesize_format = v.to_lowercase();
|
||||||
|
} else {
|
||||||
|
eprintln!("$env.config.filesize_format is not a string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End legacy options
|
||||||
x => {
|
x => {
|
||||||
eprintln!("$config.{} is an unknown config setting", x)
|
eprintln!("$env.config.{} is an unknown config setting", x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,13 +800,20 @@ impl Value {
|
|||||||
eprintln!("$env.config is not a record");
|
eprintln!("$env.config is not a record");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if legacy_options_used {
|
||||||
|
eprintln!(
|
||||||
|
r#"The format of $env.config has recently changed, and several options have been grouped into sub-records. You may need to update your config.nu file.
|
||||||
|
Please consult https://www.nushell.sh/blog/2022-11-29-nushell-0.72.html for details. Support for the old format will be removed in an upcoming Nu release."#
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn try_parse_trim_strategy(value: &Value, config: &Config) -> Result<TrimStrategy, ShellError> {
|
fn try_parse_trim_strategy(value: &Value, config: &Config) -> Result<TrimStrategy, ShellError> {
|
||||||
let map = create_map(value, config).map_err(|e| {
|
let map = create_map(value, config).map_err(|e| {
|
||||||
eprintln!("$env.config.table_trim is not a record");
|
eprintln!("$env.config.table.trim is not a record");
|
||||||
e
|
e
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@ -467,7 +823,7 @@ fn try_parse_trim_strategy(value: &Value, config: &Config) -> Result<TrimStrateg
|
|||||||
None => return Ok(TRIM_STRATEGY_DEFAULT),
|
None => return Ok(TRIM_STRATEGY_DEFAULT),
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("$config.table_trim.methodology was not provided");
|
eprintln!("$env.config.table.trim.methodology was not provided");
|
||||||
return Ok(TRIM_STRATEGY_DEFAULT);
|
return Ok(TRIM_STRATEGY_DEFAULT);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -478,7 +834,7 @@ fn try_parse_trim_strategy(value: &Value, config: &Config) -> Result<TrimStrateg
|
|||||||
if let Ok(b) = value.as_bool() {
|
if let Ok(b) = value.as_bool() {
|
||||||
*try_to_keep_words = b;
|
*try_to_keep_words = b;
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.table_trim.wrap_try_keep_words is not a bool");
|
eprintln!("$env.config.table.trim.wrapping_try_keep_words is not a bool");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +843,7 @@ fn try_parse_trim_strategy(value: &Value, config: &Config) -> Result<TrimStrateg
|
|||||||
if let Ok(v) = value.as_string() {
|
if let Ok(v) = value.as_string() {
|
||||||
*suffix = Some(v);
|
*suffix = Some(v);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("$config.table_trim.truncating_suffix is not a string")
|
eprintln!("$env.config.table.trim.truncating_suffix is not a string")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,9 +861,9 @@ fn try_parse_trim_methodology(value: &Value) -> Option<TrimStrategy> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
"truncating" => return Some(TrimStrategy::Truncate { suffix: None }),
|
"truncating" => return Some(TrimStrategy::Truncate { suffix: None }),
|
||||||
_ => eprintln!("unrecognized $config.trim_methodology value; expected values ['truncating', 'wrapping']"),
|
_ => eprintln!("unrecognized $config.table.trim.methodology value; expected either 'truncating' or 'wrapping'"),
|
||||||
},
|
},
|
||||||
Err(_) => eprintln!("$config.trim_methodology is not a string"),
|
Err(_) => eprintln!("$env.config.table.trim.methodology is not a string"),
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
|
@ -243,43 +243,55 @@ let light_theme = {
|
|||||||
|
|
||||||
# The default config record. This is where much of your global configuration is setup.
|
# The default config record. This is where much of your global configuration is setup.
|
||||||
let-env config = {
|
let-env config = {
|
||||||
external_completer: null # check 'carapace_completer' above to as example
|
ls: {
|
||||||
filesize_metric: false # true => (KB, MB, GB), false => (KiB, MiB, GiB)
|
use_ls_colors: true # use the LS_COLORS environment variable to colorize output
|
||||||
table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
|
clickable_links: true # enable or disable clickable links. Your terminal has to support links.
|
||||||
use_ls_colors: true
|
}
|
||||||
rm_always_trash: false
|
rm: {
|
||||||
|
always_trash: false # always act as if -t was given. Can be overridden with -p
|
||||||
|
}
|
||||||
|
cd: {
|
||||||
|
abbreviations: true # allows `cd s/o/f` to expand to `cd some/other/folder`
|
||||||
|
}
|
||||||
|
table: {
|
||||||
|
mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
|
||||||
|
index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column
|
||||||
|
trim: {
|
||||||
|
methodology: wrapping # wrapping or truncating
|
||||||
|
wrapping_try_keep_words: true # A strategy used by the 'wrapping' methodology
|
||||||
|
truncating_suffix: "..." # A suffix used by the 'truncating' methodology
|
||||||
|
}
|
||||||
|
}
|
||||||
|
history: {
|
||||||
|
max_size: 10000 # Session has to be reloaded for this to take effect
|
||||||
|
sync_on_enter: true # Enable to share history between multiple sessions, else you have to close the session to write history to file
|
||||||
|
file_format: "plaintext" # "sqlite" or "plaintext"
|
||||||
|
}
|
||||||
|
completions: {
|
||||||
|
case_sensitive: false # set to true to enable case-sensitive completions
|
||||||
|
quick: true # set this to false to prevent auto-selecting completions when only one remains
|
||||||
|
partial: true # set this to false to prevent partial filling of the prompt
|
||||||
|
algorithm: "prefix" # prefix or fuzzy
|
||||||
|
external: {
|
||||||
|
enable: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow
|
||||||
|
max_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
|
||||||
|
completer: null # check 'carapace_completer' above as an example
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filesize: {
|
||||||
|
metric: true # true => KB, MB, GB (ISO standard), false => KiB, MiB, GiB (Windows standard)
|
||||||
|
format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto
|
||||||
|
}
|
||||||
color_config: $dark_theme # if you want a light theme, replace `$dark_theme` to `$light_theme`
|
color_config: $dark_theme # if you want a light theme, replace `$dark_theme` to `$light_theme`
|
||||||
use_grid_icons: true
|
use_grid_icons: true
|
||||||
footer_mode: "25" # always, never, number_of_rows, auto
|
footer_mode: "25" # always, never, number_of_rows, auto
|
||||||
quick_completions: true # set this to false to prevent auto-selecting completions when only one remains
|
|
||||||
partial_completions: true # set this to false to prevent partial filling of the prompt
|
|
||||||
completion_algorithm: "prefix" # prefix, fuzzy
|
|
||||||
float_precision: 2
|
float_precision: 2
|
||||||
# buffer_editor: "emacs" # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL
|
# buffer_editor: "emacs" # command that will be used to edit the current line buffer with ctrl+o, if unset fallback to $env.EDITOR and $env.VISUAL
|
||||||
use_ansi_coloring: true
|
use_ansi_coloring: true
|
||||||
filesize_format: "auto" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto
|
|
||||||
edit_mode: emacs # emacs, vi
|
edit_mode: emacs # emacs, vi
|
||||||
max_history_size: 10000 # Session has to be reloaded for this to take effect
|
|
||||||
sync_history_on_enter: true # Enable to share the history between multiple sessions, else you have to close the session to persist history to file
|
|
||||||
history_file_format: "plaintext" # "sqlite" or "plaintext"
|
|
||||||
shell_integration: true # enables terminal markers and a workaround to arrow keys stop working issue
|
shell_integration: true # enables terminal markers and a workaround to arrow keys stop working issue
|
||||||
table_index_mode: always # "always" show indexes, "never" show indexes, "auto" = show indexes when a table has "index" column
|
|
||||||
cd_with_abbreviations: false # set to true to allow you to do things like cd s/o/f and nushell expand it to cd some/other/folder
|
|
||||||
case_sensitive_completions: false # set to true to enable case-sensitive completions
|
|
||||||
enable_external_completion: true # set to false to prevent nushell looking into $env.PATH to find more suggestions, `false` recommended for WSL users as this look up my be very slow
|
|
||||||
max_external_completion_results: 100 # setting it lower can improve completion performance at the cost of omitting some options
|
|
||||||
# A strategy of managing table view in case of limited space.
|
|
||||||
table_trim: {
|
|
||||||
methodology: wrapping, # truncating
|
|
||||||
# A strategy which will be used by 'wrapping' methodology
|
|
||||||
wrapping_try_keep_words: true,
|
|
||||||
# A suffix which will be used with 'truncating' methodology
|
|
||||||
# truncating_suffix: "..."
|
|
||||||
}
|
|
||||||
show_banner: true # true or false to enable or disable the banner
|
show_banner: true # true or false to enable or disable the banner
|
||||||
show_clickable_links_in_ls: true # true or false to enable or disable clickable links in the ls listing. your terminal has to support links.
|
|
||||||
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt.
|
render_right_prompt_on_last_line: false # true or false to enable or disable right prompt to be rendered on last line of the prompt.
|
||||||
|
|
||||||
hooks: {
|
hooks: {
|
||||||
pre_prompt: [{
|
pre_prompt: [{
|
||||||
$nothing # replace with source code to run before the prompt is shown
|
$nothing # replace with source code to run before the prompt is shown
|
||||||
|
Loading…
Reference in New Issue
Block a user