on master help sign in
Merge pull request #1082 from LordFlashmeow/master

Add alias for --paging=never

commit58dcabffe6d98b0fed066c41e07af59398c3c37f authorDavid Peter <sharkdp@users.noreply.github.com> dateThu 2 Jul 2020, 21:08 (6 years ago) parent05027b7c264f74
6 files changed+51−18
CHANGELOG.md+1 assets/completions/bat.fish.in+2 assets/manual/bat.1.in+5−6 src/bin/bat/app.rs+2 src/bin/bat/clap_app.rs+18−12 tests/integration_tests.rs+23
CHANGELOG.md+1
@@ -3,6 +3,7 @@
33## Features
44
55- Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p)
6+- Added `-P` short flag to disable paging, revised man page description, see #1075 and #1082 (@LordFlashmeow)
67
78## Bugfixes
89
assets/completions/bat.fish.in+2
@@ -52,6 +52,8 @@ complete -c {{PROJECT_EXECUTABLE}} -l paging -xka "auto never always" -d "Specif
5252
5353complete -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"
5454
55+complete -c {{PROJECT_EXECUTABLE}} -s P -d "Disable paging. Alias for '--paging=never'" -n "not __fish_seen_subcommand_from cache"
56+
5557complete -c {{PROJECT_EXECUTABLE}} -s A -l show-all -d "Show non-printable characters like space/tab/newline" -n "not __fish_seen_subcommand_from cache"
5658
5759complete -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"
assets/manual/bat.1.in+5−6
@@ -89,15 +89,14 @@ values: *auto*, never, always.
8989.HP
9090\fB\-\-paging\fR <when>
9191.IP
92−Specify when to use the pager. To control which pager is used, set the PAGER or
93−BAT_PAGER environment variables (the latter takes precedence) or use the '\-\-pager'
94−option. To disable the pager permanently, set BAT_PAGER to an empty string or set
95−\&'\-\-paging=never' in the configuration file. Possible values: *auto*, never, always.
92+Specify when to use the pager. To disable the pager, use \&'\-\-paging=never' or its alias,
93+\fB-P\fR. To disable the pager permanently, set BAT_PAGER to an empty string. To control
94+which pager is used, see the '\-\-pager' option. Possible values: *auto*, never, always.
9695.HP
9796\fB\-\-pager\fR <command>
9897.IP
99−Determine which pager is used. This option will overwrite the PAGER and BAT_PAGER
100−environment variables. The default pager is 'less'. To disable the pager completely, use
98+Determine which pager is used. This option will override the PAGER and BAT_PAGER
99+environment variables. The default pager is 'less'. To control when the pager is used, see
101100the '\-\-paging' option. Example: '\-\-pager "less \fB\-RF\fR"'.
102101.HP
103102\fB\-m\fR, \fB\-\-map\-syntax\fR <glob-pattern:syntax-name>...
src/bin/bat/app.rs+2
@@ -85,6 +85,8 @@ impl App {
8585 if self.matches.occurrences_of("plain") > 1 {
8686 // If we have -pp as an option when in auto mode, the pager should be disabled.
8787 PagingMode::Never
88+ } else if self.matches.is_present("no-paging") {
89+ PagingMode::Never
8890 } else if inputs.iter().any(Input::is_stdin) {
8991 // If we are reading from stdin, only enable paging if we write to an
9092 // interactive terminal and if we do not *read* from an interactive
src/bin/bat/clap_app.rs+18−12
@@ -265,16 +265,23 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
265265 .possible_values(&["auto", "never", "always"])
266266 .default_value("auto")
267267 .hide_default_value(true)
268− .help("Specify when to use the pager (*auto*, never, always).")
268+ .help("Specify when to use the pager, or use `-P` to disable (*auto*, never, always).")
269269 .long_help(
270− "Specify when to use the pager. To control which pager \
271− is used, set the PAGER or BAT_PAGER environment \
272− variables (the latter takes precedence) or use the '--pager' option. \
273− To disable the pager permanently, set BAT_PAGER to an empty string \
274− or set '--paging=never' in the configuration file. \
275− Possible values: *auto*, never, always.",
270+ "Specify when to use the pager. To disable the pager, use \
271+ --paging=never' or its alias,'-P'. To disable the pager permanently, \
272+ set BAT_PAGER to an empty string. To control which pager is used, see the \
273+ '--pager' option. Possible values: *auto*, never, always."
276274 ),
277275 )
276+ .arg(
277+ Arg::with_name("no-paging")
278+ .short("P")
279+ .alias("no-pager")
280+ .overrides_with("no-paging")
281+ .hidden(true)
282+ .hidden_short_help(true)
283+ .help("Alias for '--paging=never'")
284+ )
278285 .arg(
279286 Arg::with_name("pager")
280287 .long("pager")
@@ -284,11 +291,10 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
284291 .hidden_short_help(true)
285292 .help("Determine which pager to use.")
286293 .long_help(
287− "Determine which pager is used. This option will overwrite \
288− the PAGER and BAT_PAGER environment variables. The default \
289− pager is 'less'. To disable the pager completely, use the \
290− '--paging' option. \
291− Example: '--pager \"less -RF\"'.",
294+ "Determine which pager is used. This option will override the \
295+ PAGER and BAT_PAGER environment variables. The default pager is 'less'. \
296+ To control when the pager is used, see the '--paging' option. \
297+ Example: '--pager \"less -RF\"'."
292298 ),
293299 )
294300 .arg(
tests/integration_tests.rs+23
@@ -405,6 +405,29 @@ fn pager_disable() {
405405 .stdout(predicate::eq("hello world\n").normalize());
406406}
407407
408+#[test]
409+fn alias_pager_disable() {
410+ bat()
411+ .env("PAGER", "echo other-pager")
412+ .arg("-P")
413+ .arg("test.txt")
414+ .assert()
415+ .success()
416+ .stdout(predicate::eq("hello world\n").normalize());
417+}
418+
419+#[test]
420+fn alias_pager_disable_long_overrides_short() {
421+ bat()
422+ .env("PAGER", "echo pager-output")
423+ .arg("-P")
424+ .arg("--paging=always")
425+ .arg("test.txt")
426+ .assert()
427+ .success()
428+ .stdout(predicate::eq("pager-output\n").normalize());
429+}
430+
408431#[test]
409432fn config_location_test() {
410433 bat_with_config()