Skip to content

Commit

Permalink
Support DELTA_PAGER env var
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Oct 4, 2020
1 parent 166d31a commit 31e2661
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
21 changes: 12 additions & 9 deletions src/bat/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@ impl OutputType {
) -> Result<Self> {
let mut replace_arguments_to_less = false;

let pager_from_env = match (env::get_env_var("BAT_PAGER"), env::get_env_var("PAGER")) {
(Some(bat_pager), _) => Some(bat_pager),
(_, Some(pager)) => {
// less needs to be called with the '-R' option in order to properly interpret the
// ANSI color sequences printed by bat. If someone has set PAGER="less -F", we
// therefore need to overwrite the arguments and add '-R'.
//
// We only do this for PAGER (as it is not specific to 'bat'), not for BAT_PAGER
// or bats '--pager' command line option.
let pager_from_env = match (
env::get_env_var("DELTA_PAGER"),
env::get_env_var("BAT_PAGER"),
env::get_env_var("PAGER"),
) {
(Some(delta_pager), _, _) => Some(delta_pager),
(None, Some(bat_pager), _) => Some(bat_pager),
(None, None, Some(pager)) => {
// less needs to be called with the '-R' option in order to properly interpret ANSI
// color sequences. If someone has set PAGER="less -F", we therefore need to
// overwrite the arguments and add '-R'.
// We only do this for PAGER, since it is used in other contexts.
replace_arguments_to_less = true;
Some(pager)
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,8 @@ pub struct Opt {
pub inspect_raw_lines: String,

/// Whether to use a pager when displaying output. Options are: auto, always, and never. The
/// default pager is `less`: this can be altered by setting the environment variables BAT_PAGER
/// or PAGER (BAT_PAGER has priority).
/// default pager is `less`: this can be altered by setting the environment variables
/// DELTA_PAGER, BAT_PAGER, or PAGER (and that is their order of priority).
#[structopt(long = "paging", default_value = "auto")]
pub paging_mode: String,

Expand Down
2 changes: 1 addition & 1 deletion src/options/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn is_no_syntax_highlighting_syntax_theme_name(theme_name: &str) -> bool {
///
/// Basically:
/// 1. The theme is specified by the `--theme` option. If this isn't supplied then it is specified
/// by the `BAT_PAGER` environment variable.
/// by the `BAT_THEME` environment variable.
/// 2. Light vs dark mode is specified by the `--light` or `--dark` options. If these aren't
/// supplied then it is inferred from the chosen theme.
///
Expand Down

1 comment on commit 31e2661

@torarnv
Copy link
Contributor

@torarnv torarnv commented on 31e2661 Oct 4, 2020

Choose a reason for hiding this comment

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

Nice!

Please sign in to comment.