# Description This PR tries to respect a person's locale setting with date/time in the default right prompt. This also restores the right prompt so that it does not load from the US default from reedline. closes https://github.com/nushell/nushell/issues/9924 Here's the fromat reference if anyone thinks there's a better time format. I could be talked into `%c` maybe. https://docs.rs/chrono/latest/chrono/format/strftime/index.html # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
79 lines
3.0 KiB
Plaintext
79 lines
3.0 KiB
Plaintext
# Nushell Environment Config File
|
|
#
|
|
# version = "0.84.1"
|
|
|
|
def create_left_prompt [] {
|
|
let home = $nu.home-path
|
|
|
|
let dir = ([
|
|
($env.PWD | str substring 0..($home | str length) | str replace $home "~"),
|
|
($env.PWD | str substring ($home | str length)..)
|
|
] | str join)
|
|
|
|
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
|
|
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
|
|
let path_segment = $"($path_color)($dir)"
|
|
|
|
$path_segment | str replace --all (char path_sep) $"($separator_color)/($path_color)"
|
|
}
|
|
|
|
def create_right_prompt [] {
|
|
# create a right prompt in magenta with green separators and am/pm underlined
|
|
let time_segment = ([
|
|
(ansi reset)
|
|
(ansi magenta)
|
|
(date now | format date '%x %X %p') # try to respect user's locale
|
|
] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
|
|
str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
|
|
|
|
let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
|
|
(ansi rb)
|
|
($env.LAST_EXIT_CODE)
|
|
] | str join)
|
|
} else { "" }
|
|
|
|
([$last_exit_code, (char space), $time_segment] | str join)
|
|
}
|
|
|
|
# Use nushell functions to define your right and left prompt
|
|
$env.PROMPT_COMMAND = {|| create_left_prompt }
|
|
# FIXME: This default is not implemented in rust code as of 2023-09-08.
|
|
$env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
|
|
|
|
# The prompt indicators are environmental variables that represent
|
|
# the state of the prompt
|
|
$env.PROMPT_INDICATOR = {|| "> " }
|
|
$env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
|
|
$env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
|
|
$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 external commands (to_string)
|
|
# Note: The conversions happen *after* config.nu is loaded
|
|
$env.ENV_CONVERSIONS = {
|
|
"PATH": {
|
|
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
|
|
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
|
|
}
|
|
"Path": {
|
|
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
|
|
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
|
|
}
|
|
}
|
|
|
|
# Directories to search for scripts when calling source or use
|
|
$env.NU_LIB_DIRS = [
|
|
# FIXME: This default is not implemented in rust code as of 2023-09-06.
|
|
($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
|
|
]
|
|
|
|
# Directories to search for plugin binaries when calling register
|
|
$env.NU_PLUGIN_DIRS = [
|
|
# FIXME: This default is not implemented in rust code as of 2023-09-06.
|
|
($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
|
|
]
|
|
|
|
# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
|
|
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
|