Skip to content

Commit

Permalink
config: set $LESS and $LESSCHARSET even if $PAGER is set
Browse files Browse the repository at this point in the history
Our current default for `ui.pager` is this:

```toml
ui.pager = { command = ["less"], env_default = { LESS = "-FRX", LESSCHARSET = "utf-8" } }
```

If the user has `$PAGER` set, we take that value and replace the above
table by a scalar set to the value from the environment variable. That
means that anyone who has set `$PAGER` to just `less` will lose both
the `-FRX` and the charset, making e.g. colored output from `jj`
result in escaped ANSI codes rendered by `less`. The lack of those
options might not matter for other tools they use so they might not
have realized that they wanted those options.

This patch attempts to improve the situation by setting the value from
`$PAGER` in `ui.pager.command` so the rest of the config is left
alone.

The default config will still be ignored if you set the scalar
`ui.pager` to e.g. `less`, since that overrides the table.

Closes #2926
  • Loading branch information
martinvonz committed May 10, 2024
1 parent 0e841bd commit f195670
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,18 @@ fn env_base() -> config::Config {
builder = builder.set_override("ui.color", "never").unwrap();
}
if let Ok(value) = env::var("PAGER") {
builder = builder.set_override("ui.pager", value).unwrap();
builder = builder
.set_override(
"ui.pager.command",
config::Value::new(
None,
config::ValueKind::Array(vec![config::Value::new(
None,
config::ValueKind::String(value),
)]),
),
)
.unwrap();
}
if let Ok(value) = env::var("VISUAL") {
builder = builder.set_override("ui.editor", value).unwrap();
Expand Down

0 comments on commit f195670

Please sign in to comment.