Advertisement
disu1950

Nushell Environment Config File

Jul 4th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.27 KB | None | 0 0
  1. # Nushell Environment Config File
  2. #
  3. # version = "0.95.1"
  4.  
  5. def create_left_prompt [] {
  6.     let dir = match (do --ignore-shell-errors { $env.PWD | path relative-to $nu.home-path }) {
  7.         null => $env.PWD
  8.         '' => '~'
  9.         $relative_pwd => ([~ $relative_pwd] | path join)
  10.     }
  11.  
  12.     let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
  13.     let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
  14.     let path_segment = $"($path_color)($dir)"
  15.  
  16.     $path_segment | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
  17. }
  18.  
  19. def create_right_prompt [] {
  20.     # create a right prompt in magenta with green separators and am/pm underlined
  21.     let time_segment = ([
  22.         (ansi reset)
  23.         (ansi magenta)
  24.         (date now | format date '%x %X') # try to respect user's locale
  25.     ] | str join | str replace --regex --all "([/:])" $"(ansi green)${1}(ansi magenta)" |
  26.         str replace --regex --all "([AP]M)" $"(ansi magenta_underline)${1}")
  27.  
  28.     let last_exit_code = if ($env.LAST_EXIT_CODE != 0) {([
  29.         (ansi rb)
  30.         ($env.LAST_EXIT_CODE)
  31.     ] | str join)
  32.     } else { "" }
  33.  
  34.     ([$last_exit_code, (char space), $time_segment] | str join)
  35. }
  36.  
  37. # Use nushell functions to define your right and left prompt
  38. $env.PROMPT_COMMAND = {|| create_left_prompt }
  39. # FIXME: This default is not implemented in rust code as of 2023-09-08.
  40. $env.PROMPT_COMMAND_RIGHT = {|| create_right_prompt }
  41.  
  42. # The prompt indicators are environmental variables that represent
  43. # the state of the prompt
  44. $env.PROMPT_INDICATOR = {|| "> " }
  45. $env.PROMPT_INDICATOR_VI_INSERT = {|| ": " }
  46. $env.PROMPT_INDICATOR_VI_NORMAL = {|| "> " }
  47. $env.PROMPT_MULTILINE_INDICATOR = {|| "::: " }
  48.  
  49. # If you want previously entered commands to have a different prompt from the usual one,
  50. # you can uncomment one or more of the following lines.
  51. # This can be useful if you have a 2-line prompt and it's taking up a lot of space
  52. # because every command entered takes up 2 lines instead of 1. You can then uncomment
  53. # the line below so that previously entered commands show with a single `🚀`.
  54. # $env.TRANSIENT_PROMPT_COMMAND = {|| "🚀 " }
  55. # $env.TRANSIENT_PROMPT_INDICATOR = {|| "" }
  56. # $env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT = {|| "" }
  57. # $env.TRANSIENT_PROMPT_INDICATOR_VI_NORMAL = {|| "" }
  58. # $env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = {|| "" }
  59. # $env.TRANSIENT_PROMPT_COMMAND_RIGHT = {|| "" }
  60.  
  61. # Specifies how environment variables are:
  62. # - converted from a string to a value on Nushell startup (from_string)
  63. # - converted from a value back to a string when running external commands (to_string)
  64. # Note: The conversions happen *after* config.nu is loaded
  65. $env.ENV_CONVERSIONS = {
  66.     "PATH": {
  67.         from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
  68.         to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
  69.     }
  70.     "Path": {
  71.         from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
  72.         to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
  73.     }
  74. }
  75.  
  76. # Directories to search for scripts when calling source or use
  77. # The default for this is $nu.default-config-dir/scripts
  78. $env.NU_LIB_DIRS = [
  79.     ($nu.default-config-dir | path join 'scripts') # add <nushell-config-dir>/scripts
  80.     ($nu.data-dir | path join 'completions') # default home for nushell completions
  81. ]
  82.  
  83. # Directories to search for plugin binaries when calling register
  84. # The default for this is $nu.default-config-dir/plugins
  85. $env.NU_PLUGIN_DIRS = [
  86.     ($nu.default-config-dir | path join 'plugins') # add <nushell-config-dir>/plugins
  87. ]
  88.  
  89. # To add entries to PATH (on Windows you might use Path), you can use the following pattern:
  90. # $env.PATH = ($env.PATH | split row (char esep) | prepend '/some/path')
  91. # An alternate way to add entries to $env.PATH is to use the custom command `path add`
  92. # which is built into the nushell stdlib:
  93. # use std "path add"
  94. # $env.PATH = ($env.PATH | split row (char esep))
  95. # path add /some/path
  96. # path add ($env.CARGO_HOME | path join "bin")
  97. # path add ($env.HOME | path join ".local" "bin")
  98. # $env.PATH = ($env.PATH | uniq)
  99.  
  100. # To load from a custom file you can use:
  101. # source ($nu.default-config-dir | path join 'custom.nu')
Tags: Shell BASH nu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement