1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-10-31 07:04:04 +00:00

Compare commits

...

10 Commits

Author SHA1 Message Date
Justin Su
4e13c3eb5b Update CHANGELOG.md
Also fix a typo from the previous release
2025-10-20 19:23:26 +02:00
Justin Su
7e55608975 docs: Clarify that -X/--no-init is not added on modern versions of less 2025-10-20 19:23:26 +02:00
Justin Su
4bd5cbca8e docs: Mention less options by short+long names 2025-10-20 19:23:26 +02:00
Keith Hall
7c3fa7e1ce Merge pull request #3448 from akinomyoga/bash-fullquote
Use `-o fullquote` and `-o noquote` for more robust escaping in Bash completions
2025-10-20 19:55:56 +03:00
Koichi Murase
3188a147d8 Use "-o fullquote" and "-o noquote" to escape Bash completions 2025-10-20 19:38:54 +09:00
Koichi Murase
926fbc4b13 Fix indentation of the Bash completion file 2025-10-20 17:59:48 +09:00
Keith Hall
006d77fa39 Merge pull request #3442 from lmmx/patch-1
fix: allow hyphen values to `-r`/`--line-range`
2025-10-19 23:44:25 +03:00
Louis Maddox
52a792d46f fix: allow hyphen values to -r/--line-range
via #2944
2025-10-19 21:24:59 +01:00
Keith Hall
20db989fb1 Merge pull request #3441 from sharkdp/prepare_changelog
Prepare changelog for future changes
2025-10-19 21:40:50 +03:00
Keith Hall
2c63d3c792 Prepare changelog for future changes 2025-10-19 21:24:54 +03:00
6 changed files with 71 additions and 20 deletions

View File

@@ -1,3 +1,22 @@
# unreleased
## Features
## Bugfixes
- Fix negative values of N not being parsed in <N:M> line ranges without `=` flag value separator, see #3442 (@lmmx)
## Other
- Improve README documentation on pager options passed to less, see #3443 (@injust)
- Use more robust approach to escaping in Bash completions, see #3448 (@akinomyoga)
## Syntaxes
## Themes
## `bat` as a library
# v0.26.0
## Features
@@ -29,7 +48,7 @@
- Update base16 README links to community driven base16 work #2871 (@JamyGolden)
- Work around build failures when building `bat` from vendored sources #3179 (@dtolnay)
- CICD: Stop building for x86_64-pc-windows-gnu which fails #3261 (Enselic)
- CICD: CICD: replace windows-2019 runners with windows-2025 #3339 (@cyqsimon)
- CICD: replace windows-2019 runners with windows-2025 #3339 (@cyqsimon)
- Build script: replace string-based codegen with quote-based codegen #3340 (@cyqsimon)
- Improve code coverage of `--list-languages` parameter #2942 (@sblondon)
- Only start offload worker thread when there's more than 1 core #2956 (@cyqsimon)

View File

@@ -670,22 +670,22 @@ to improve the experience. Specifically, `-R`/`--RAW-CONTROL-CHARS`, `-F`/`--qui
> - The `--paging=always` argument is used.
> - The `BAT_PAGING` environment is set to `always`.
The `-R` option is needed to interpret ANSI colors correctly.
The `-R`/`--RAW-CONTROL-CHARS` option is needed to interpret ANSI colors correctly.
The `-F` option instructs `less` to exit immediately if the output size is smaller than
The `-F`/`--quit-if-one-screen` option instructs `less` to exit immediately if the output size is smaller than
the vertical size of the terminal. This is convenient for small files because you do not
have to press `q` to quit the pager.
The `-K` option instructs `less` to exit immediately when an interrupt signal is received.
The `-K`/`--quit-on-intr` option instructs `less` to exit immediately when an interrupt signal is received.
This is useful to ensure that `less` quits together with `bat` on SIGINT.
The `-X` option is needed to fix a bug with the `--quit-if-one-screen` feature in versions
of `less` older than version 530. Unfortunately, it also breaks mouse-wheel support in `less`.
The `-X`/`--no-init` option is added to versions of `less` older than version 530 (older than 558 on Windows) to
fix a bug with the `-F`/`--quit-if-one-screen` feature. Unfortunately, it also breaks mouse-wheel support in `less`.
If you want to enable mouse-wheel scrolling on older versions of `less` and do not mind losing
the quit-if-one-screen feature, you can set the pager (via `--pager` or `BAT_PAGER`) to `less -R`.
For `less` 530 or newer, it should work out of the box.
The `-S` option is added when `bat`'s `-S`/`--chop-long-lines` option is used. This tells `less`
The `-S`/`--chop-long-lines` option is added when `bat`'s `-S`/`--chop-long-lines` option is used. This tells `less`
to truncate any lines larger than the terminal width.
### Indentation

View File

@@ -14,18 +14,36 @@ __bat_escape_completions()
{
# Do not escape if completing a quoted value.
[[ $cur == [\"\']* ]] && return 0
# printf -v to an array index is available in bash >= 4.1.
# Use it if available, as -o filenames is semantically incorrect if
# we are not actually completing filenames, and it has side effects
# (e.g. adds trailing slash to candidates matching present dirs).
if ((
BASH_VERSINFO[0] > 5 || \
BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3
)); then
# bash >= 5.3 has "compopt -o fullquote", which exactly does
# what this function tries to do.
compopt -o fullquote
elif ((
BASH_VERSINFO[0] > 4 || \
BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] > 0
)); then
# printf -v to an array index is available in bash >= 4.1.
# Use it if available, as -o filenames is semantically
# incorrect if we are not actually completing filenames, and it
# has side effects (e.g. adds trailing slash to candidates
# matching present dirs).
local i
for i in ${!COMPREPLY[*]}; do
printf -v "COMPREPLY[i]" %q "${COMPREPLY[i]}"
done
# We can use "compopt -o noquote" available in bash >= 4.3 to
# prevent further quoting by the shell, which would be
# unexpectedly applied when a quoted result matches a filename.
if ((
BASH_VERSINFO[0] > 4 || \
BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 3
)); then
compopt -o noquote
fi
else
compopt -o filenames
fi
@@ -66,7 +84,7 @@ _bat() {
printf "%s\n" "$lang"
done
)" -- "$cur"))
__bat_escape_completions
__bat_escape_completions
return 0
;;
-H | --highlight-line | \
@@ -130,16 +148,16 @@ _bat() {
return 0
;;
--theme)
local IFS=$'\n'
COMPREPLY=($(compgen -W "auto${IFS}auto:always${IFS}auto:system${IFS}dark${IFS}light${IFS}$("$1" --list-themes)" -- "$cur"))
__bat_escape_completions
return 0
;;
local IFS=$'\n'
COMPREPLY=($(compgen -W "auto${IFS}auto:always${IFS}auto:system${IFS}dark${IFS}light${IFS}$("$1" --list-themes)" -- "$cur"))
__bat_escape_completions
return 0
;;
--theme-dark | \
--theme-light)
local IFS=$'\n'
COMPREPLY=($(compgen -W "$("$1" --list-themes)" -- "$cur"))
__bat_escape_completions
__bat_escape_completions
return 0
;;
--style)
@@ -158,7 +176,7 @@ _bat() {
numbers
snip
)
# shellcheck disable=SC2016
# shellcheck disable=SC2016
if declare -F _comp_delimited >/dev/null 2>&1; then
# bash-completion > 2.11
_comp_delimited , -W '"${styles[@]}"'

View File

@@ -194,6 +194,7 @@ Options:
'--line-range :40' prints lines 1 to 40
'--line-range 40:' prints lines 40 to the end of the file
'--line-range 40' only prints line 40
'--line-range -10:' prints the last 10 lines
'--line-range 30:+10' prints lines 30 to 40
'--line-range 35::5' prints lines 30 to 40 (line 35 with 5 lines of context)
'--line-range 30:40:2' prints lines 28 to 42 (range 30-40 with 2 lines of context)

View File

@@ -519,6 +519,7 @@ pub fn build_app(interactive_output: bool) -> Command {
.short('r')
.action(ArgAction::Append)
.value_name("N:M")
.allow_hyphen_values(true)
.help("Only print the lines from N to M.")
.long_help(
"Only print the specified range of lines for each file. \
@@ -527,6 +528,7 @@ pub fn build_app(interactive_output: bool) -> Command {
'--line-range :40' prints lines 1 to 40\n \
'--line-range 40:' prints lines 40 to the end of the file\n \
'--line-range 40' only prints line 40\n \
'--line-range -10:' prints the last 10 lines\n \
'--line-range 30:+10' prints lines 30 to 40\n \
'--line-range 35::5' prints lines 30 to 40 (line 35 with 5 lines of context)\n \
'--line-range 30:40:2' prints lines 28 to 42 (range 30-40 with 2 lines of context)",

View File

@@ -207,7 +207,7 @@ fn line_range_from_back_last_two() {
}
#[test]
fn line_range_from_back_last_two_single_line() {
fn line_range_from_back_last_two_single_line_eq_sep() {
bat()
.arg("single-line.txt")
.arg("--line-range=-2:")
@@ -216,6 +216,17 @@ fn line_range_from_back_last_two_single_line() {
.stdout("Single Line");
}
#[test]
fn line_range_from_back_last_two_single_line_no_sep() {
bat()
.arg("single-line.txt")
.arg("--line-range")
.arg("-2:")
.assert()
.success()
.stdout("Single Line");
}
#[test]
fn line_range_first_two() {
bat()