Skip to content

Configurable built-in prompts - #2064

Merged
sophiajt merged 3 commits into
nushell:masterfrom
sophiajt:do_ansi_prompt
Jun 26, 2020
Merged

sophiajt merged 3 commits into
nushell:masterfrom
sophiajt:do_ansi_prompt

Conversation

@sophiajt

Copy link
Copy Markdown
Contributor

The PR adds a few features that work together to allow you to configure your built-in prompt by setting the prompt config setting. This will point to a pipeline that runs and creates the prompt. This works similarly to the startup, with a focus of running a single pipeline to create the prompt.

To help create prompts, we have a few new commands:

  • ansi - which creates ANSI color codes. For example ansi blue will return the ansi color code to change the font blue
  • do - which runs the block given to completion, optionally ignoring errors

Another update to help was to add sterr redirection. We will now redirect stderr if part of the pipeline, turning the text into error values which are sent to commands later in the pipeline.

Here's an example prompt that shows the pwd and the current git branch, each given a separate color. It also ignores any error if the git branch is missing:

> config --set [prompt '= `{{$(ansi green)}}{{$(pwd)}}{{$(do -i { git rev-parse --abbrev-ref HEAD | trim | format " {$(ansi reset)}({$(ansi blue)}{$it}{$(ansi reset)})" })}}{{$(ansi reset)}}> `']

Screenshot from 2020-06-27 10-09-35

@sophiajt
sophiajt merged commit 0578160 into nushell:master Jun 26, 2020
@sophiajt
sophiajt deleted the do_ansi_prompt branch June 26, 2020 22:37
}

fn signature(&self) -> Signature {
Signature::build("with-env")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this signature right? Just seems odd to have with-env in the midst of do

This was referenced Jun 28, 2020
@m-kru

m-kru commented Jul 28, 2021

Copy link
Copy Markdown

@jntrnr any up to date example how to set it? The documentation is missing and the example you have provided does not work anymore as there have been some breaking changes.

I am trying simple things like:

config set prompt `pwd`
config set prompt `$pwd`
config set prompt `{$(pwd)}`

etc. but none seems to work. I always get command not found.

@fdncred

fdncred commented Jul 29, 2021

Copy link
Copy Markdown
Contributor

@m-kru string interpolation changed a few releases ago. Try something like $"(pwd)"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants