mirror of
https://github.com/sharkdp/bat.git
synced 2025-10-31 23:22:03 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5371426588 | ||
|
|
4e13c3eb5b | ||
|
|
7e55608975 | ||
|
|
4bd5cbca8e | ||
|
|
7c3fa7e1ce | ||
|
|
3188a147d8 | ||
|
|
926fbc4b13 | ||
|
|
006d77fa39 | ||
|
|
52a792d46f | ||
|
|
20db989fb1 | ||
|
|
2c63d3c792 |
21
CHANGELOG.md
21
CHANGELOG.md
@@ -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)
|
||||
|
||||
12
README.md
12
README.md
@@ -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
|
||||
|
||||
42
assets/completions/bat.bash.in
vendored
42
assets/completions/bat.bash.in
vendored
@@ -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[@]}"'
|
||||
|
||||
@@ -6,12 +6,12 @@ if you are not looking for a program like `bat`, this comparison might not be fo
|
||||
|
||||
| | bat | [pygments](http://pygments.org/) | [highlight](http://www.andre-simon.de/doku/highlight/highlight.php) | [ccat](https://github.com/jingweno/ccat) | [source-highlight](https://www.gnu.org/software/src-highlite/) | [hicat](https://github.com/rstacruz/hicat) | [coderay](https://github.com/rubychan/coderay) | [rouge](https://github.com/jneen/rouge) | [clp](https://github.com/jpe90/clp) |
|
||||
|----------------------------------------------|---------------------------------------------------------------------|----------------------------------|---------------------------------------------------------------------|------------------------------------------|----------------------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|
|
||||
| Drop-in `cat` replacement | :heavy_check_mark: [*](https://github.com/sharkdp/bat/issues/134) | :x: | :x: | (:heavy_check_mark:) | :x: | :x: [*](https://github.com/rstacruz/hicat/issues/6) | :x: | :x: | :x: |
|
||||
| Drop-in `cat` replacement | :heavy_check_mark: [*](https://github.com/sharkdp/bat/issues/134) | :x: | :x: | (✔️) | :x: | :x: [*](https://github.com/rstacruz/hicat/issues/6) | :x: | :x: | :x: |
|
||||
| Git integration | :heavy_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :x: |
|
||||
| Automatic paging | :heavy_check_mark: | :x: | :x: | :x: | :x: | :heavy_check_mark: | :x: | :x: | :x: |
|
||||
| Languages (circa) | 150 | 300 | 200 | 7 | 80 | 130 | 30 | 130 | 150 |
|
||||
| Extensible (languages, themes) | :heavy_check_mark: | (:heavy_check_mark:) | (:heavy_check_mark:) | :x: | (:heavy_check_mark:) | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| Advanced highlighting (e.g. nested syntaxes) | :heavy_check_mark: | :heavy_check_mark: | (:heavy_check_mark:) ? | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Extensible (languages, themes) | :heavy_check_mark: | (✔️) | (✔️) | :x: | (✔️) | :x: | :x: | :x: | :heavy_check_mark: |
|
||||
| Advanced highlighting (e.g. nested syntaxes) | :heavy_check_mark: | :heavy_check_mark: | (✔️) ? | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Execution time [ms] (`jquery-3.3.1.js`) | 422 | 455 | 299 | 39 | 208 | 287 | 128 | 740 | 22 |
|
||||
| Execution time [ms] (`miniz.c`) | 27 | 169 | 19 | 4 | 36 | 131 | 58 | 231 | 4 |
|
||||
| Execution time [ms] (957 kB XML file) | 215 | 296 | 236 | 165 | 83 | 412 | 135 | 386 | 127 |
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user