Home Explore Blog CI



nushell

2nd chunk of `blog/2020-06-30-nushell_0_16_0.md`
397aab5ab66aabe1e2a9301ceb9d0f8f632d54bb3c1a355000000001000006a7
- `char` - makes it possible to output newlines and tabs (sophiajt)
- `do` - runs a block to completion, optionally ignoring errors (sophiajt)

## Custom prompts (sophiajt)

You can now run a pipeline which returns a string, or list of strings, that is used to create a custom prompt. To do so, set the pipeline you want to use in the config for the `prompt` setting.

A simple example:

```
> config --set [prompt "echo '> '"]
```

We've also added a new `ansi` command to let you change the color. Let's use it to change the prompt to blue:

```
> config --set [prompt "echo $(ansi blue) '> '"]
```

You can make the prompt even fancier. For example, this prompt prints the current directory, git branch, and current date and time:

```
> config --set [prompt 'echo [ $(ansi green) $(pwd) $(ansi reset) $(do -i {git rev-parse --abbrev-ref HEAD } | trim | echo [ "(" $(ansi blue) $it $(ansi reset) ")" ] | str join) $(char newline) $(ansi cyan) $(date --format "%d/%m/%Y %H:%M:%S").formatted $(ansi reset) "> " ]']
```



_Example of full prompt_

Or update your prompt to show an abbreviated path:

```
> config --set [prompt 'echo [ $(ansi green) $(pwd | split row "/" | first $(pwd | split row "/" | count | = $it - 1 ) | each { str substring "0,1" | format "{$it}/" } | append $(pwd | split row "/" | last ) | str join) $(do -i { git rev-parse --abbrev-ref HEAD | trim | echo $(ansi reset) "(" $(ansi blue) $it $(ansi reset) ")" | str join }) $(ansi reset) "> "]']
```

(note: the above assumes Unix-based systems, so on Windows use "\" as the path separator))


Title: Nushell 0.16.0: Custom Prompts Configuration
Summary
Nushell 0.16.0 allows users to create custom prompts by running a pipeline that returns a string or list of strings. The `prompt` setting in the config can be set to a pipeline, and the new `ansi` command can be used to change the color. Example configurations are provided to display the current directory, Git branch, and current date and time, as well as an abbreviated path.