[update] Upate nushell configs to reflect the latest changes
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
let-env STARSHIP_SHELL = "nu"
|
||||
let-env STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
let-env PROMPT_MULTILINE_INDICATOR = (^/usr/bin/starship prompt --continuation)
|
||||
$env.STARSHIP_SHELL = "nu"
|
||||
$env.STARSHIP_SESSION_KEY = (random chars -l 16)
|
||||
$env.PROMPT_MULTILINE_INDICATOR = (^starship prompt --continuation)
|
||||
|
||||
# Does not play well with default character module.
|
||||
# TODO: Also Use starship vi mode indicators?
|
||||
let-env PROMPT_INDICATOR = ""
|
||||
$env.PROMPT_INDICATOR = ""
|
||||
|
||||
let-env PROMPT_COMMAND = { ||
|
||||
$env.PROMPT_COMMAND = { ||
|
||||
# jobs are not supported
|
||||
let width = (term size).columns
|
||||
^/usr/bin/starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
^starship prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
}
|
||||
|
||||
# Whether we have config items
|
||||
let has_config_items = (not ($env | get -i config | is-empty))
|
||||
|
||||
let-env config = if $has_config_items {
|
||||
$env.config = if $has_config_items {
|
||||
$env.config | upsert render_right_prompt_on_last_line true
|
||||
} else {
|
||||
{render_right_prompt_on_last_line: true}
|
||||
}
|
||||
|
||||
let-env PROMPT_COMMAND_RIGHT = { ||
|
||||
$env.PROMPT_COMMAND_RIGHT = { ||
|
||||
let width = (term size).columns
|
||||
^/usr/bin/starship prompt --right $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
^starship prompt --right $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
# Initialize hook to add new entries to the database.
|
||||
if (not ($env | default false __zoxide_hooked | get __zoxide_hooked)) {
|
||||
let-env __zoxide_hooked = true
|
||||
let-env config = ($env | default {} config).config
|
||||
let-env config = ($env.config | default {} hooks)
|
||||
let-env config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
||||
let-env config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
||||
let-env config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
|
||||
$env.__zoxide_hooked = true
|
||||
$env.config = ($env | default {} config).config
|
||||
$env.config = ($env.config | default {} hooks)
|
||||
$env.config = ($env.config | update hooks ($env.config.hooks | default {} env_change))
|
||||
$env.config = ($env.config | update hooks.env_change ($env.config.hooks.env_change | default [] PWD))
|
||||
$env.config = ($env.config | update hooks.env_change.PWD ($env.config.hooks.env_change.PWD | append {|_, dir|
|
||||
zoxide add -- $dir
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ let light_theme = {
|
||||
|
||||
|
||||
# The default config record. This is where much of your global configuration is setup.
|
||||
let-env config = {
|
||||
$env.config = {
|
||||
ls: {
|
||||
use_ls_colors: true # use the LS_COLORS environment variable to colorize output
|
||||
clickable_links: true # enable or disable clickable links. Your terminal has to support links.
|
||||
@@ -654,3 +654,4 @@ let-env config = {
|
||||
source starship.nu
|
||||
source zoxide.nu
|
||||
source alias.nu
|
||||
use conda.nu
|
||||
|
||||
@@ -12,28 +12,28 @@ def create_left_prompt [] {
|
||||
|
||||
def create_right_prompt [] {
|
||||
let time_segment = ([
|
||||
(date now | date format '%m/%d/%Y %r')
|
||||
(date now | format date '%m/%d/%Y %r')
|
||||
] | str join)
|
||||
|
||||
$time_segment
|
||||
}
|
||||
|
||||
# Use nushell functions to define your right and left prompt
|
||||
let-env PROMPT_COMMAND = { create_left_prompt }
|
||||
let-env PROMPT_COMMAND_RIGHT = { create_right_prompt }
|
||||
$env.PROMPT_COMMAND = { create_left_prompt }
|
||||
$env.PROMPT_COMMAND_RIGHT = { create_right_prompt }
|
||||
|
||||
# The prompt indicators are environmental variables that represent
|
||||
# the state of the prompt
|
||||
let-env PROMPT_INDICATOR = { "〉" }
|
||||
let-env PROMPT_INDICATOR_VI_INSERT = { ": " }
|
||||
let-env PROMPT_INDICATOR_VI_NORMAL = { "〉" }
|
||||
let-env PROMPT_MULTILINE_INDICATOR = { "::: " }
|
||||
$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
|
||||
let-env ENV_CONVERSIONS = {
|
||||
$env.ENV_CONVERSIONS = {
|
||||
"PATH": {
|
||||
from_string: { |s| $s | split row (char esep) | path expand -n }
|
||||
to_string: { |v| $v | path expand -n | str join (char esep) }
|
||||
@@ -47,7 +47,7 @@ let-env ENV_CONVERSIONS = {
|
||||
# Directories to search for scripts when calling source or use
|
||||
#
|
||||
# By default, <nushell-config-dir>/scripts is added
|
||||
let-env NU_LIB_DIRS = [
|
||||
$env.NU_LIB_DIRS = [
|
||||
($nu.config-path | path dirname | path join 'scripts')
|
||||
($nu.config-path | path dirname | path join 'conf.d')
|
||||
]
|
||||
@@ -55,16 +55,16 @@ let-env NU_LIB_DIRS = [
|
||||
# Directories to search for plugin binaries when calling register
|
||||
#
|
||||
# By default, <nushell-config-dir>/plugins is added
|
||||
let-env NU_PLUGIN_DIRS = [
|
||||
$env.NU_PLUGIN_DIRS = [
|
||||
($nu.config-path | path dirname | path join 'plugins')
|
||||
]
|
||||
|
||||
load-env (fnm env --shell bash | lines | str replace 'export ' '' | str replace -a '"' '' | split column = | rename name value | where name != "FNM_ARCH" and name != "PATH" | reduce -f {} {|it, acc| $acc | upsert $it.name $it.value })
|
||||
|
||||
# To add entries to PATH (on Windows you might use Path), you can use the following pattern:
|
||||
# let-env PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
|
||||
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
|
||||
# macOS ARM64 (Apple Silicon)
|
||||
let-env PATH = ($env.PATH | split row (char esep) | prepend '/opt/homebrew/bin')
|
||||
let-env PATH = ($env.PATH | prepend $"($env.FNM_MULTISHELL_PATH)/bin")
|
||||
$env.PATH = ($env.PATH | split row (char esep) | prepend '/opt/homebrew/bin')
|
||||
$env.PATH = ($env.PATH | prepend $"($env.FNM_MULTISHELL_PATH)/bin")
|
||||
# Linux
|
||||
# let-env PATH = ($env.PATH | split row (char esep) | prepend '/home/linuxbrew/.linuxbrew/bin')
|
||||
# $env.PATH = ($env.PATH | split row (char esep) | prepend '/home/linuxbrew/.linuxbrew/bin')
|
||||
|
||||
89
config/nushell/scripts/conda.nu
Normal file
89
config/nushell/scripts/conda.nu
Normal file
@@ -0,0 +1,89 @@
|
||||
export-env {
|
||||
$env.CONDA_BASE_PATH = (if ((sys).host.name == "Windows") {$env.Path} else {$env.PATH})
|
||||
|
||||
let info = (
|
||||
if not (which mamba | is-empty) {
|
||||
(mamba info --envs --json | from json)
|
||||
} else if not (which conda | is-empty) {
|
||||
(conda info --envs --json | from json)
|
||||
} else {
|
||||
('{"root_prefix": "", "envs": ""}' | from json)
|
||||
})
|
||||
|
||||
$env.CONDA_ROOT = $info.root_prefix
|
||||
|
||||
$env.CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc|
|
||||
if $it == $info.root_prefix {
|
||||
$acc | upsert "base" $it
|
||||
} else {
|
||||
$acc | upsert ($it | path basename) $it
|
||||
}})
|
||||
|
||||
$env.CONDA_CURR = null
|
||||
}
|
||||
|
||||
export def-env activate [name: string] {
|
||||
if ($env.CONDA_ROOT | is-empty) {
|
||||
print "Neither Conda nor Mamba is valid."
|
||||
return
|
||||
}
|
||||
|
||||
if not ($name in $env.CONDA_ENVS) {
|
||||
print $"Environment ($name) is invalid. Available:"
|
||||
print $env.CONDA_ENVS
|
||||
return
|
||||
}
|
||||
|
||||
let new_path = (
|
||||
if ((sys).host.name == "Windows") {
|
||||
update-path-windows ($env.CONDA_ENVS | get $name)
|
||||
} else {
|
||||
update-path-linux ($env.CONDA_ENVS | get $name)
|
||||
})
|
||||
|
||||
load-env ({CONDA_CURR: $name} | merge $new_path)
|
||||
}
|
||||
|
||||
export def-env deactivate [] {
|
||||
if ($env.CONDA_ROOT | is-empty) {
|
||||
print "Neither Conda nor Mamba is valid."
|
||||
return
|
||||
}
|
||||
|
||||
$env.CONDA_CURR = null
|
||||
|
||||
load-env {Path: $env.CONDA_BASE_PATH, PATH: $env.CONDA_BASE_PATH}
|
||||
}
|
||||
|
||||
export def-env list [] {
|
||||
$env.CONDA_ENVS |
|
||||
flatten |
|
||||
transpose |
|
||||
rename name path |
|
||||
insert active { |it| $it.name == $env.CONDA_CURR } |
|
||||
move path --after active
|
||||
}
|
||||
|
||||
def update-path-linux [env_path: path] {
|
||||
let env_path = [
|
||||
$env_path,
|
||||
([$env_path, "bin"] | path join)
|
||||
]
|
||||
|
||||
return {
|
||||
Path: ($env.PATH | prepend $env_path),
|
||||
PATH: ($env.PATH | prepend $env_path)
|
||||
}
|
||||
}
|
||||
|
||||
def update-path-windows [env_path: path] {
|
||||
let env_path = [
|
||||
$env_path,
|
||||
([$env_path, "Scripts"] | path join),
|
||||
]
|
||||
|
||||
return {
|
||||
Path: ($env.Path | prepend $env_path),
|
||||
PATH: ($env.Path | prepend $env_path)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user