From 2575aae945a78b5d976c0a21faba730b7bc837f1 Mon Sep 17 00:00:00 2001 From: Dash Peters Date: Tue, 30 Jun 2020 12:18:17 -0700 Subject: [PATCH 1/4] Add short flag for --paging=never --- src/bin/bat/app.rs | 2 ++ src/bin/bat/clap_app.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 432b8c57..4793c4fb 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -85,6 +85,8 @@ impl App { if self.matches.occurrences_of("plain") > 1 { // If we have -pp as an option when in auto mode, the pager should be disabled. PagingMode::Never + } else if self.matches.is_present("disable-paging") { + PagingMode::Never } else if inputs.iter().any(Input::is_stdin) { // If we are reading from stdin, only enable paging if we write to an // interactive terminal and if we do not *read* from an interactive diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 4182b76e..b7c371fe 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -275,6 +275,12 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { Possible values: *auto*, never, always.", ), ) + .arg( + Arg::with_name("disable-paging") + .short("P") + .overrides_with("disable-paging") + .help("Alias for --paging=never") + ) .arg( Arg::with_name("pager") .long("pager") From bfac6fd85c43caf0b24ff1b9c9619d1099360a2c Mon Sep 17 00:00:00 2001 From: Dash Peters Date: Tue, 30 Jun 2020 12:41:50 -0700 Subject: [PATCH 2/4] Add integration tests --- tests/integration_tests.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index c1fce864..7991083b 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -405,6 +405,29 @@ fn pager_disable() { .stdout(predicate::eq("hello world\n").normalize()); } +#[test] +fn alias_pager_disable() { + bat() + .env("PAGER", "echo other-pager") + .arg("-P") + .arg("test.txt") + .assert() + .success() + .stdout(predicate::eq("hello world\n").normalize()); +} + +#[test] +fn alias_pager_disable_long_overrides_short() { + bat() + .env("PAGER", "echo pager-output") + .arg("-P") + .arg("--paging=always") + .arg("test.txt") + .assert() + .success() + .stdout(predicate::eq("pager-output\n").normalize()); +} + #[test] fn config_location_test() { bat_with_config() From 5fdeeabb444c3c23e9785c13b79768c54c97c57d Mon Sep 17 00:00:00 2001 From: Dash Peters Date: Wed, 1 Jul 2020 21:35:45 -0700 Subject: [PATCH 3/4] Change to name no-paging, add long flag and alias --- src/bin/bat/app.rs | 2 +- src/bin/bat/clap_app.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 4793c4fb..6c61215e 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -85,7 +85,7 @@ impl App { if self.matches.occurrences_of("plain") > 1 { // If we have -pp as an option when in auto mode, the pager should be disabled. PagingMode::Never - } else if self.matches.is_present("disable-paging") { + } else if self.matches.is_present("no-paging") { PagingMode::Never } else if inputs.iter().any(Input::is_stdin) { // If we are reading from stdin, only enable paging if we write to an diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index b7c371fe..f249321e 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -276,9 +276,11 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { ), ) .arg( - Arg::with_name("disable-paging") + Arg::with_name("no-paging") .short("P") - .overrides_with("disable-paging") + .long("no-paging") + .alias("no-pager") + .overrides_with("no-paging") .help("Alias for --paging=never") ) .arg( From c264f747714a42318f1b33309778560ff9d6a8b0 Mon Sep 17 00:00:00 2001 From: Dash Peters Date: Thu, 2 Jul 2020 00:07:37 -0700 Subject: [PATCH 4/4] Hide alias in help, update man and completions A long alias doesn't make sense, since `--paging=never` already exists --- CHANGELOG.md | 1 + assets/completions/bat.fish.in | 2 ++ assets/manual/bat.1.in | 11 +++++------ src/bin/bat/clap_app.rs | 26 ++++++++++++-------------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d45641..23ad7ae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Features - Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p) +- Added `-P` short flag to disable paging, revised man page description, see #1075 and #1082 (@LordFlashmeow) ## Bugfixes diff --git a/assets/completions/bat.fish.in b/assets/completions/bat.fish.in index bf22fe9b..420a227f 100644 --- a/assets/completions/bat.fish.in +++ b/assets/completions/bat.fish.in @@ -52,6 +52,8 @@ complete -c {{PROJECT_EXECUTABLE}} -l paging -xka "auto never always" -d "Specif complete -c {{PROJECT_EXECUTABLE}} -s p -l plain -d "Only show plain style, no decorations. Alias for '--style=plain'" -n "not __fish_seen_subcommand_from cache" +complete -c {{PROJECT_EXECUTABLE}} -s P -d "Disable paging. Alias for '--paging=never'" -n "not __fish_seen_subcommand_from cache" + complete -c {{PROJECT_EXECUTABLE}} -s A -l show-all -d "Show non-printable characters like space/tab/newline" -n "not __fish_seen_subcommand_from cache" complete -c {{PROJECT_EXECUTABLE}} -l style -xka "auto full plain changes header grid numbers" -d "Comma-separated list of style elements or presets to display with file contents" -n "not __fish_seen_subcommand_from cache" diff --git a/assets/manual/bat.1.in b/assets/manual/bat.1.in index 6345bde5..740d69e4 100644 --- a/assets/manual/bat.1.in +++ b/assets/manual/bat.1.in @@ -89,15 +89,14 @@ values: *auto*, never, always. .HP \fB\-\-paging\fR .IP -Specify when to use the pager. To control which pager is used, set the PAGER or -BAT_PAGER environment variables (the latter takes precedence) or use the '\-\-pager' -option. To disable the pager permanently, set BAT_PAGER to an empty string or set -\&'\-\-paging=never' in the configuration file. Possible values: *auto*, never, always. +Specify when to use the pager. To disable the pager, use \&'\-\-paging=never' or its alias, +\fB-P\fR. To disable the pager permanently, set BAT_PAGER to an empty string. To control +which pager is used, see the '\-\-pager' option. Possible values: *auto*, never, always. .HP \fB\-\-pager\fR .IP -Determine which pager is used. This option will overwrite the PAGER and BAT_PAGER -environment variables. The default pager is 'less'. To disable the pager completely, use +Determine which pager is used. This option will override the PAGER and BAT_PAGER +environment variables. The default pager is 'less'. To control when the pager is used, see the '\-\-paging' option. Example: '\-\-pager "less \fB\-RF\fR"'. .HP \fB\-m\fR, \fB\-\-map\-syntax\fR ... diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index f249321e..730a2175 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -265,23 +265,22 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { .possible_values(&["auto", "never", "always"]) .default_value("auto") .hide_default_value(true) - .help("Specify when to use the pager (*auto*, never, always).") + .help("Specify when to use the pager, or use `-P` to disable (*auto*, never, always).") .long_help( - "Specify when to use the pager. To control which pager \ - is used, set the PAGER or BAT_PAGER environment \ - variables (the latter takes precedence) or use the '--pager' option. \ - To disable the pager permanently, set BAT_PAGER to an empty string \ - or set '--paging=never' in the configuration file. \ - Possible values: *auto*, never, always.", + "Specify when to use the pager. To disable the pager, use \ + --paging=never' or its alias,'-P'. To disable the pager permanently, \ + set BAT_PAGER to an empty string. To control which pager is used, see the \ + '--pager' option. Possible values: *auto*, never, always." ), ) .arg( Arg::with_name("no-paging") .short("P") - .long("no-paging") .alias("no-pager") .overrides_with("no-paging") - .help("Alias for --paging=never") + .hidden(true) + .hidden_short_help(true) + .help("Alias for '--paging=never'") ) .arg( Arg::with_name("pager") @@ -292,11 +291,10 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { .hidden_short_help(true) .help("Determine which pager to use.") .long_help( - "Determine which pager is used. This option will overwrite \ - the PAGER and BAT_PAGER environment variables. The default \ - pager is 'less'. To disable the pager completely, use the \ - '--paging' option. \ - Example: '--pager \"less -RF\"'.", + "Determine which pager is used. This option will override the \ + PAGER and BAT_PAGER environment variables. The default pager is 'less'. \ + To control when the pager is used, see the '--paging' option. \ + Example: '--pager \"less -RF\"'." ), ) .arg(