Skip to content

Commit

Permalink
replace let-env FOO = ... by $env.FOO = ... (nushell#972)
Browse files Browse the repository at this point in the history
command used:
```nushell
sd --string-mode "let-env " '$env.' book/**/*
```
  • Loading branch information
amtoine committed Jul 25, 2023
1 parent 68b315e commit 0aa7b02
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 130 deletions.
20 changes: 10 additions & 10 deletions book/3rdpartyprompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you like [oh-my-posh](https://ohmyposh.dev/), you can use oh-my-posh with Nus
3. Set the PROMPT_COMMAND in ~/.config/nushell/config.nu(or the path output by `$nu.config-path`), change `M365Princess.omp.json` to whatever you like [Themes demo](https://ohmyposh.dev/docs/themes).

```shell
> let-env PROMPT_COMMAND = { oh-my-posh --config ~/.poshthemes/M365Princess.omp.json }
> $env.PROMPT_COMMAND = { oh-my-posh --config ~/.poshthemes/M365Princess.omp.json }
```
For MacOS users:
Expand All @@ -36,9 +36,9 @@ let posh_theme = $'($posh_dir)/share/oh-my-posh/themes/'
# Change the theme names to: zash/space/robbyrussel/powerline/powerlevel10k_lean/
# material/half-life/lambda Or double lines theme: amro/pure/spaceship, etc.
# For more [Themes demo](https://ohmyposh.dev/docs/themes)
let-env PROMPT_COMMAND = { || oh-my-posh prompt print primary --config $'($posh_theme)/zash.omp.json' }
$env.PROMPT_COMMAND = { || oh-my-posh prompt print primary --config $'($posh_theme)/zash.omp.json' }
# Optional
let-env PROMPT_INDICATOR = $"(ansi y)$> (ansi reset)"
$env.PROMPT_INDICATOR = $"(ansi y)$> (ansi reset)"
```
## Starship
Expand All @@ -54,22 +54,22 @@ let-env PROMPT_INDICATOR = $"(ansi y)$> (ansi reset)"
Here's an example config section for Starship:
```
let-env STARSHIP_SHELL = "nu"
$env.STARSHIP_SHELL = "nu"
def create_left_prompt [] {
starship prompt --cmd-duration $env.CMD_DURATION_MS $'--status=($env.LAST_EXIT_CODE)'
}
# Use nushell functions to define your right and left prompt
let-env PROMPT_COMMAND = { || create_left_prompt }
let-env PROMPT_COMMAND_RIGHT = ""
$env.PROMPT_COMMAND = { || create_left_prompt }
$env.PROMPT_COMMAND_RIGHT = ""
# The prompt indicators are environmental variables that represent
# the state of the prompt
let-env PROMPT_INDICATOR = ""
let-env PROMPT_INDICATOR_VI_INSERT = ": "
let-env PROMPT_INDICATOR_VI_NORMAL = "〉"
let-env PROMPT_MULTILINE_INDICATOR = "::: "
$env.PROMPT_INDICATOR = ""
$env.PROMPT_INDICATOR_VI_INSERT = ": "
$env.PROMPT_INDICATOR_VI_NORMAL = "〉"
$env.PROMPT_MULTILINE_INDICATOR = "::: "
```
Now restart Nu.
Expand Down
14 changes: 7 additions & 7 deletions book/coloring_and_theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Many parts of Nushell's interface can have their color customized. All of these
Table borders are controlled by the `table_mode` setting in `config.nu`. Here is an example:

```shell
> let-env config = {
> $env.config = {
table_mode: rounded
}
```
Expand Down Expand Up @@ -346,7 +346,7 @@ Here's the current list of flat shapes.
Here's a small example of how to apply color to these items. Anything not specified will receive the default color.

```shell
> let-env config = {
> $env.config = {
color_config: {
shape_garbage: { fg: "#FFFFFF" bg: "#FF0000" attr: b}
shape_bool: green
Expand All @@ -370,13 +370,13 @@ The Nushell prompt is configurable through these environment variables and confi
Example: For a simple prompt one could do this. Note that `PROMPT_COMMAND` requires a `block` whereas the others require a `string`.
```shell
> let-env PROMPT_COMMAND = { build-string (date now | date format '%m/%d/%Y %I:%M:%S%.3f') ': ' (pwd | path basename) }
> $env.PROMPT_COMMAND = { build-string (date now | date format '%m/%d/%Y %I:%M:%S%.3f') ': ' (pwd | path basename) }
```
If you don't like the default `PROMPT_INDICATOR` you could change it like this.
```shell
> let-env PROMPT_INDICATOR = "> "
> $env.PROMPT_INDICATOR = "> "
```
If you're using `starship`, you'll most likely want to show the right prompt on the last line of the prompt, just like zsh or fish. You could modify the `config.nu` file, just set `render_right_prompt_on_last_line` to true:
Expand All @@ -400,7 +400,7 @@ There's an exhaustive list [here](https://github.com/trapd00r/LS_COLORS), which
I like the `vivid` application and currently have it configured in my `config.nu` like this. You can find `vivid` [here](https://github.com/sharkdp/vivid).
`let-env LS_COLORS = (vivid generate molokai | str trim)`
`$env.LS_COLORS = (vivid generate molokai | str trim)`
If `LS_COLORS` is not set, nushell will default to a built-in `LS_COLORS` setting, based on 8-bit (extended) ANSI colors.
Expand Down Expand Up @@ -498,7 +498,7 @@ Nushell's default config file contains a light theme definition, if you are work
```shell
# in $nu.config-file
let-env config = {
$env.config = {
...
color_config: $dark_theme # if you want a light theme, replace `$dark_theme` to `$light_theme`
...
Expand All @@ -509,7 +509,7 @@ You can just change it to light theme by replacing `$dark_theme` to `$light_them
```shell
# in $nu.config-file
let-env config = {
$env.config = {
...
color_config: $light_theme # if you want a light theme, replace `$dark_theme` to `$light_theme`
...
Expand Down
6 changes: 3 additions & 3 deletions book/coming_from_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If you're coming from `Git Bash` on Windows, then the external commands you're u
To make these commands available in `nu` as well, add the following line to your `config.nu` with either `append` or `prepend`.

```
let-env Path = ($env.Path | prepend 'C:\Program Files\Git\usr\bin')
$env.Path = ($env.Path | prepend 'C:\Program Files\Git\usr\bin')
```

Note: this table assumes Nu 0.60.0 or later.
Expand Down Expand Up @@ -48,11 +48,11 @@ Note: this table assumes Nu 0.60.0 or later.
| `cargo b --jobs=$(nproc)` | `cargo b $"--jobs=(sys \| get cpu \| length)"` | Use command output in an option |
| `echo $PATH` | `$env.PATH` (Non-Windows) or `$env.Path` (Windows) | See the current path |
| `<update ~/.bashrc>` | `vim $nu.config-path` | Update PATH permanently |
| `export PATH = $PATH:/usr/other/bin` | `let-env PATH = ($env.PATH \| append /usr/other/bin)` | Update PATH temporarily |
| `export PATH = $PATH:/usr/other/bin` | `$env.PATH = ($env.PATH \| append /usr/other/bin)` | Update PATH temporarily |
| `export` | `$env` | List the current environment variables |
| `<update ~/.bashrc>` | `vim $nu.config-path` | Update environment variables permanently |
| `FOO=BAR ./bin` | `FOO=BAR ./bin` | Update environment temporarily |
| `export FOO=BAR` | `let-env FOO = BAR` | Set environment variable for current session |
| `export FOO=BAR` | `$env.FOO = BAR` | Set environment variable for current session |
| `echo $FOO` | `$env.FOO` | Use environment variables |
| `unset FOO` | `hide-env FOO` | Unset environment variable for current session |
| `alias s="git status -sb"` | `alias s = git status -sb` | Define an alias temporarily |
Expand Down
Loading

0 comments on commit 0aa7b02

Please sign in to comment.