DEV Community

Benjamin DeCoste
Benjamin DeCoste

Posted on


Customizing nushell prompt

By default, nushell's prompt shows your working directory on the left, and the date & time on the right. It looks like this:

nushell default prompt

As someone who was trying nu after using zsh for a long time, I wanted to replicate my old prompt, which showed me my working directory, current kubernetes cluster, and current k8s namespace:

zsh prompt

Nushell configures your prompt in its environment script ($nu.env-path). If you open this file you will see two functions at the very top, create_left_prompt and create_right_prompt. you can see the default implementation for the date

def create_right_prompt [] {
    let time_segment = ([
        (date now | date format '%m/%d/%Y %r')
    ] | str join)

Enter fullscreen mode Exit fullscreen mode

I created a new function for my k8s prompt. I liked having the time on the prompt, so I left that (thought I didn't feel like I needed the date).

def kube_prompt [] {
    let k_prompt =  ([(kubectl ctx -c), (kubectl ns -c)] | str trim | str join '/')
    let d_prompt = ([(date now | date format '%r')] | str join)
    $"\(($k_prompt)\) ($d_prompt)"
Enter fullscreen mode Exit fullscreen mode

Just below, we can edit the let-env PROMPT_COMMAND_RIGHT to look like:

let-env PROMPT_COMMAND_RIGHT = { kube_prompt }
Enter fullscreen mode Exit fullscreen mode

Restarting your shell and you will see the new prompt

nushell with k8s prompt

Oldest comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git