Using Nushell on MacOS
Published Fri Feb 23 2024I like Nushell a lot for scripting. When I originally tried it as my shell I found the UX lacking compared with Fish out of the box. Another thing that I find mildly irritating is the configuration path for MacOS being ~/Library/Application Support/nushell
. There are some very long threads on this jam packed with pednatry if you wish to seek them out. I decided I’d give it another try, this time conceding to use the above configuration path.
Configuring Path
The first thing that is immediately missing from the nu shell experience is absence of my homebrew tools and apps from path. This can be fixed easily by adding homebrew to our path:
# ~/Library/Application Support/nushell/env.nu
$env.PATH = (
$env.PATH
| split row (char esep)
| prepend '/opt/homebrew/bin'
| prepend '~/.cargo/bin'
)
Nushell is not yet stable, my generated env.nu
file was old enough that the commented out syntax was now invalid.
# 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')
Luckily there was a very helpful error message to tell me what to use $env
instead of let-env
.
Starship
My next essential configuration item was my prompt. Without my prompt the shell just doesn’t feel right. I use Starship which works across multiple shells, the Nushell docs include an example configuration for it as well.
# Use nushell functions to define your right and left prompt
$env.PROMPT_COMMAND = { || create_left_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 = "::: "
With my configured prompt and path I can now use Nushell productively! I am missing my aliases from Fish (specifically my git ones), but there is always more to configure.