mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 23:39:48 +02:00
Use environment variable for env_conversions (#4566)
* Handle string->value env conv. with env. var. Also adds the environment variable for Path/PATH and removes it from config. * Simplify getting the string->value conversion * Refactor env conversion into its own function * Use env var for to_string conversion; Remove conf * Fix indentation in default config
This commit is contained in:
@@ -89,7 +89,7 @@ pub(crate) fn evaluate(
|
||||
}
|
||||
|
||||
// Translate environment variables from Strings to Values
|
||||
if let Some(e) = convert_env_values(engine_state, &stack, &config) {
|
||||
if let Some(e) = convert_env_values(engine_state, &stack) {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &e);
|
||||
std::process::exit(1);
|
||||
|
@@ -25,6 +25,20 @@ let-env PROMPT_INDICATOR_VI_INSERT = ": "
|
||||
let-env PROMPT_INDICATOR_VI_NORMAL = "〉"
|
||||
let-env PROMPT_MULTILINE_INDICATOR = "::: "
|
||||
|
||||
# Specifies how environment variables are:
|
||||
# - converted from a string to a value on Nushell startup (from_string)
|
||||
# - converted from a value back to a string when running extrnal commands (to_string)
|
||||
let-env ENV_CONVERSIONS = {
|
||||
"PATH": {
|
||||
from_string: { |s| $s | split row (char esep) }
|
||||
to_string: { |v| $v | str collect (char esep) }
|
||||
}
|
||||
"Path": {
|
||||
from_string: { |s| $s | split row (char esep) }
|
||||
to_string: { |v| $v | str collect (char esep) }
|
||||
}
|
||||
}
|
||||
|
||||
# Custom completions for external commands (those outside of Nushell)
|
||||
# Each completions has two parts: the form of the external command, including its flags and parameters
|
||||
# and a helper command that knows how to complete values for those flags and parameters
|
||||
@@ -93,7 +107,7 @@ extern "git push" [
|
||||
--ipv6(-6) # use IPv6 addresses only
|
||||
]
|
||||
|
||||
# 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 $config = {
|
||||
filesize_metric: $false
|
||||
table_mode: rounded # basic, compact, compact_double, light, thin, with_love, rounded, reinforced, heavy, none, other
|
||||
@@ -124,12 +138,6 @@ let $config = {
|
||||
float_precision: 2
|
||||
use_ansi_coloring: $true
|
||||
filesize_format: "b" # b, kb, kib, mb, mib, gb, gib, tb, tib, pb, pib, eb, eib, zb, zib, auto
|
||||
env_conversions: {
|
||||
"PATH": {
|
||||
from_string: { |s| $s | split row (char esep) }
|
||||
to_string: { |v| $v | str collect (char esep) }
|
||||
}
|
||||
}
|
||||
edit_mode: emacs # emacs, vi
|
||||
max_history_size: 10000
|
||||
menu_config: {
|
||||
@@ -141,11 +149,11 @@ let $config = {
|
||||
marker: "| "
|
||||
}
|
||||
history_config: {
|
||||
page_size: 10
|
||||
selector: ":"
|
||||
text_style: green
|
||||
selected_text_style: green_reverse
|
||||
marker: "? "
|
||||
page_size: 10
|
||||
selector: ":"
|
||||
text_style: green
|
||||
selected_text_style: green_reverse
|
||||
marker: "? "
|
||||
}
|
||||
keybindings: [
|
||||
{
|
||||
|
@@ -34,18 +34,8 @@ pub(crate) fn evaluate(
|
||||
},
|
||||
);
|
||||
|
||||
let config = match stack.get_config() {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
report_error(&working_set, &e);
|
||||
Config::default()
|
||||
}
|
||||
};
|
||||
|
||||
// Translate environment variables from Strings to Values
|
||||
if let Some(e) = convert_env_values(engine_state, &stack, &config) {
|
||||
if let Some(e) = convert_env_values(engine_state, &stack) {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &e);
|
||||
std::process::exit(1);
|
||||
|
13
src/repl.rs
13
src/repl.rs
@@ -59,17 +59,6 @@ pub(crate) fn evaluate(
|
||||
config_files::read_config_file(engine_state, &mut stack, config_file);
|
||||
let history_path = config_files::create_history_path();
|
||||
|
||||
// Load config struct form config variable
|
||||
let config = match stack.get_config() {
|
||||
Ok(config) => config,
|
||||
Err(e) => {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
|
||||
report_error(&working_set, &e);
|
||||
Config::default()
|
||||
}
|
||||
};
|
||||
|
||||
// logger(|builder| {
|
||||
// configure(&config.log_level, builder)?;
|
||||
// // trace_filters(self, builder)?;
|
||||
@@ -88,7 +77,7 @@ pub(crate) fn evaluate(
|
||||
}
|
||||
|
||||
// Translate environment variables from Strings to Values
|
||||
if let Some(e) = convert_env_values(engine_state, &stack, &config) {
|
||||
if let Some(e) = convert_env_values(engine_state, &stack) {
|
||||
let working_set = StateWorkingSet::new(engine_state);
|
||||
report_error(&working_set, &e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user