Skip to content

Commit 04ad7a5

Browse files
authored
Fix and extend LS_COLORS documentation (#1771)
Resolves #1754
1 parent 586f0c5 commit 04ad7a5

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

book/coloring_and_theming.md

+36-6
Original file line numberDiff line numberDiff line change
@@ -412,17 +412,47 @@ hide-env TRANSIENT_PROMPT_COMMAND
412412

413413
## `LS_COLORS` Colors for the [`ls`](/commands/docs/ls.md) Command
414414

415-
Nushell will respect and use the `LS_COLORS` environment variable setting on Mac, Linux, and Windows. This setting allows you to define the color of file types when you do a [`ls`](/commands/docs/ls.md). For instance, you can make directories one color, _.md markdown files another color, _.toml files yet another color, etc. There are a variety of ways to color your file types.
415+
Nushell will respect and use the `LS_COLORS` environment variable setting on Mac, Linux, and Windows. This setting allows you to define the coloring of file types when you do a [`ls`](/commands/docs/ls.md). For instance, you can make directories one color, `.md` Markdown files another color, `.toml` files yet another color, etc. There are a variety of ways to color and style your file types.
416416

417-
There's an exhaustive list [here](https://github.com/trapd00r/LS_COLORS), which is overkill, but gives you an rudimentary understanding of how to create a ls_colors file that `dircolors` can turn into a `LS_COLORS` environment variable.
417+
If `LS_COLORS` is not set, nushell will default to a built-in `LS_COLORS` setting, based on [8-bit (extended) ANSI colors](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit).
418418

419-
[This](https://www.linuxhowto.net/how-to-set-colors-for-ls-command/) is a pretty good introduction to `LS_COLORS`. I'm sure you can find many more tutorials on the web.
419+
### Understanding `LS_COLORS`
420420

421-
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).
421+
`LS_COLORS` contains a colon (`:`) separated list of records that map file types and file names to styling attributes (`selector=attributes`).
422422

423-
`$env.LS_COLORS = (vivid generate molokai | str trim)`
423+
The selector can be a file type specified like `di` for "directory identifier", or `*.nu` for files with the `.nu` file extension.
424424

425-
If `LS_COLORS` is not set, nushell will default to a built-in `LS_COLORS` setting, based on 8-bit (extended) ANSI colors.
425+
The attributes are a list of semicolon (`;`) separated numbers. Note that which attributes and attribute formats are supported depends on the terminal you are using.
426+
427+
- Style attributes like `0` normal, `1` bold, `3` italic, `5` blink, [etc](https://en.wikipedia.org/wiki/ANSI_escape_code#Select_Graphic_Rendition_parameters)
428+
- [Foreground colors](https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit) `30`-`37` and `90`-`97`
429+
- [Background colors](https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit) `40`-`47` and `100`-`107`
430+
- [RGB foreground](https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit) prefixed with `38;2`, optionally followed by additional attributes
431+
- [RGB background](https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit) prefixed with `48;2`, optionally followed by additional attributes
432+
433+
For example:
434+
435+
`$env.LS_COLORS = "di=1;34:*.nu=3;33;46"`: Bold directories, italic yellow foreground cyan background `*.nu` files
436+
437+
`$env.LS_COLORS = "di=48;2;200;0;0;5"`: Red background blinking directories
438+
439+
### vivid Themes
440+
441+
For example, you can use the third-party tool [vivid](https://github.com/sharkdp/vivid), which runs on multiple platforms, has [many themes defined](https://github.com/sharkdp/vivid/tree/master/themes), and generates a `LS_COLORS` configuration from it.
442+
443+
After downloading and extracting the binary, you can use it with:
444+
445+
```nu
446+
$env.LS_COLORS = (vivid generate molokai)
447+
```
448+
449+
or with an alternative theme:
450+
451+
```nu
452+
$env.LS_COLORS = (vivid generate ayu)
453+
```
454+
455+
You can put this command into your [Nushell configuration](/book/configuration.md) for it to become the default coloring.
426456

427457
## Theming
428458

0 commit comments

Comments
 (0)