1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-01 10:52:24 +01:00

Compare commits

..

18 Commits

Author SHA1 Message Date
Martin Nordholts
0655ecf23d Prepare for v0.20.0 release
Since we have added new enum variants to the `StyleComponent` which was
not previously marked `#[non_exhaustive]`, we must bump left-most
non-zero version number (see
[specifying-dependencies](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-cratesio)).
Otherwise client code that do exhaustive matches on `StyleComponent`
will stop compiling.
2022-02-27 07:39:22 +01:00
Martin Nordholts
671fc952bc release-checklist.md: Add tip on how to review the man page 2022-02-27 07:39:22 +01:00
Martin Nordholts
3c057aa590 Add header-filename and header-filesize where missing 2022-02-27 07:39:22 +01:00
Martin Nordholts
8e8c350391 release-checklist.md: Remove '## Dependencies' 2022-02-26 17:08:32 +01:00
Martin Nordholts
1ee49b4d97 CONTRIBUTING.md: Encourage regression tests (#2089)
* CONTRIBUTING.md: Encourage regression tests

* Add colon before listing pros of regression tests

Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com>
2022-02-26 17:03:54 +01:00
cyqsimon
14ddda0a8b Recognize files in $XDG_CONFIG_HOME/git/ and $HOME/.config/git/ better (#2067)
* git global config - lookup $XDG_CONFIG_HOME faithfully

* Use `bool::then`

* Cover both `$XDG_CONFIG_HOME` & `$HOME/.config`

* Remove unused import

* Global git config tests

* Added trailing newline

* Fix git config test

* Wrote to changelog

* Revert change of `Result::ok` to `Result::unwrap`

* Apply suggestions from code review

Co-authored-by: Martin Nordholts <enselic@gmail.com>

* Guard against empty `$HOME`

Co-authored-by: Martin Nordholts <enselic@gmail.com>
2022-02-26 17:01:00 +01:00
yuuji.yaginuma
36093dd3bc Fix a repology badge in READMEs
`https://repology.org/project/bat/` doesn't exist now.
2022-02-26 13:54:02 +01:00
Josh Pencheon
ad6cae433a fix Bash completion on macOS (#2074)
* fix Bash completion on macOS

The Homebrew-provided bash-completion is version 1.x,
which doesn't provide _init_completion. We add a standard
shim instead.

* Add entry to CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>

* review: avoid calling _split_longopt repeatedly

Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
2022-02-24 07:57:23 +01:00
ltdk
e4f6fb2afe Add JQ syntax highlighting 2022-02-14 19:14:19 +01:00
Mahdi Dibaiee
d21f1e8f17 Underline highlighted lines in ANSI theme (#1985)
* Underline highlighted lines in ANSI theme

* add test for ansi highlight underline, fix underscore in plain
2022-02-14 19:02:14 +01:00
Martin Nordholts
f6ce5d2054 Write # Defaults are used in the file
To make it clear that the file intentionally contains no configuration options.
If it is completely empty it might look like a mistake on first sight.
2022-02-10 07:01:31 +01:00
cyqsimon
b60225051d Add empty rustfmt to enfore default formatter settings 2022-02-10 07:01:31 +01:00
David Peter
f2166ec6ec Add additional note to sponsors.md 2022-02-09 21:57:52 +01:00
David Peter
491d32cbf3 Minor README change 2022-02-09 21:55:16 +01:00
Keith Hall
478712be38 make further improvements to docs relating to sponsors 2022-02-09 21:54:32 +01:00
Keith Hall
d5d2fc4016 create separate sponsors.md file 2022-02-09 21:54:32 +01:00
Keith Hall
ed7cd1c45b improve sponsor section in readme 2022-02-09 21:54:32 +01:00
Keith Hall
f340893a21 Add WorkOS sponsor to readme 2022-02-09 21:54:32 +01:00
26 changed files with 300 additions and 31 deletions

3
.gitmodules vendored
View File

@@ -236,3 +236,6 @@
[submodule "assets/syntaxes/02_Extra/Dart"]
path = assets/syntaxes/02_Extra/Dart
url = https://github.com/elMuso/Dartlight.git
[submodule "assets/syntaxes/02_Extra/SublimeJQ"]
path = assets/syntaxes/02_Extra/SublimeJQ
url = https://github.com/zogwarg/SublimeJQ.git

View File

@@ -1,12 +1,13 @@
# unreleased
# v0.20.0
## Features
- New style component `header-filesize` to show size of the displayed file in the header. See #1988 (@mdibaiee)
- Use underline for line highlighting on ANSI, see #1730 (@mdibaiee)
## Bugfixes
## Other
- Fix bash completion on bash 3.x and bash-completion 1.x. See #2066 (@joshpencheon)
## Syntaxes
@@ -14,12 +15,14 @@
- Associate `_vimrc` and `_gvimrc` files with the `VimL` syntax. See #2002
- Associate `poetry.lock` files with the `TOML` syntax. See #2049
- Associate `.mesh`, `.task`, `.rgen`, `.rint`, `.rahit`, `.rchit`, `.rmiss`, and `.rcall` with the `GLSL` syntax. See #2050
## Themes
- Added support for `JQ` syntax, see #2072
- Properly associate global git config files rooted in `$XDG_CONFIG_HOME/git/` or `$HOME/.config/git/`. See #2067 (@cyqsimon)
## `bat` as a library
- Exposed `get_syntax_set` and `get_theme` methods on `HighlightingAssets`. See #2030 (@dandavison)
- Added `HeaderFilename` and `HeaderFilesize` to `StyleComponent` enum, and mark it `#[non_exhaustive]`. See #1988 (@mdibaiee)
# v0.19.0

View File

@@ -46,3 +46,25 @@ If you really think that a particular syntax or theme should be added for all
users, please read the corresponding
[documentation](https://github.com/sharkdp/bat/blob/master/doc/assets.md)
first.
## Regression tests
You are strongly encouraged to add regression tests. Regression tests are great,
not least because they:
* ensure that your contribution will never completely stop working,
* makes code review easier, because it becomes very clear what the code is
supposed to do.
For functional changes, you most likely want to add a test to
[`tests/integration_tests.rs`](https://github.com/sharkdp/bat/blob/master/tests/integration_tests.rs).
Look at existing tests to know how to write a new test. In short, you will
invoke the `bat` binary with a certain set of arguments, and then assert on
stdout/stderr.
To learn how to write regression tests for theme and syntax changes, read the
[Syntax
tests](https://github.com/sharkdp/bat/blob/master/doc/assets.md#syntax-tests)
section in `assets.md`.

2
Cargo.lock generated
View File

@@ -74,7 +74,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd"
[[package]]
name = "bat"
version = "0.19.0"
version = "0.20.0"
dependencies = [
"ansi_colours",
"ansi_term",

View File

@@ -6,7 +6,7 @@ homepage = "https://github.com/sharkdp/bat"
license = "MIT/Apache-2.0"
name = "bat"
repository = "https://github.com/sharkdp/bat"
version = "0.19.0"
version = "0.20.0"
exclude = ["assets/syntaxes/*", "assets/themes/*"]
build = "build.rs"
edition = '2018'

View File

@@ -21,7 +21,7 @@
### Sponsors
a special thank you goes to our biggest <a href="doc/sponsors.md">sponsors</a>:<br>
A special *thank you* goes to our biggest <a href="doc/sponsors.md">sponsors</a>:<br>
<a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=bat&utm_source=github">
<img src="doc/sponsors/workos-logo-white-bg.svg" width="200" alt="WorkOS">
<br>

View File

@@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script
[CompletionResult]::new('-m', 'm', [CompletionResultType]::ParameterName, 'Use the specified syntax for files matching the glob pattern (''*.cpp:C++'').')
[CompletionResult]::new('--map-syntax', 'map-syntax', [CompletionResultType]::ParameterName, 'Use the specified syntax for files matching the glob pattern (''*.cpp:C++'').')
[CompletionResult]::new('--theme', 'theme', [CompletionResultType]::ParameterName, 'Set the color theme for syntax highlighting.')
[CompletionResult]::new('--style', 'style', [CompletionResultType]::ParameterName, 'Comma-separated list of style elements to display (*auto*, full, plain, changes, header, grid, rule, numbers, snip).')
[CompletionResult]::new('--style', 'style', [CompletionResultType]::ParameterName, 'Comma-separated list of style elements to display (*auto*, full, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip).')
[CompletionResult]::new('-r', 'r', [CompletionResultType]::ParameterName, 'Only print the lines from N to M.')
[CompletionResult]::new('--line-range', 'line-range', [CompletionResultType]::ParameterName, 'Only print the lines from N to M.')
[CompletionResult]::new('-A', 'A', [CompletionResultType]::ParameterName, 'Show non-printable characters (space, tab, newline, ..).')

View File

@@ -2,9 +2,22 @@
# Requires https://github.com/scop/bash-completion
# Macs have bash3 for which the bash-completion package doesn't include
# _init_completion. This is a minimal version of that function.
__bat_init_completion()
{
COMPREPLY=()
_get_comp_words_by_ref "$@" cur prev words cword
}
_bat() {
local cur prev words cword split
_init_completion -s || return 0
local cur prev words cword split=false
if declare -F _init_completion >/dev/null 2>&1; then
_init_completion -s || return 0
else
__bat_init_completion -n "=" || return 0
_split_longopt && split=true
fi
if [[ ${words[1]-} == cache ]]; then
case $prev in

View File

@@ -56,7 +56,7 @@ complete -c {{PROJECT_EXECUTABLE}} -s P -d "Disable paging. Alias for '--paging=
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 rule numbers snip" -d "Comma-separated list of style elements or presets to display with file contents" -n "not __fish_seen_subcommand_from cache"
complete -c {{PROJECT_EXECUTABLE}} -l style -xka "auto full plain changes header header-filename header-filesize grid rule numbers snip" -d "Comma-separated list of style elements or presets to display with file contents" -n "not __fish_seen_subcommand_from cache"
complete -c {{PROJECT_EXECUTABLE}} -l tabs -x -d "<T> Set the tab width to T spaces (width of 0 passes tabs through directly)" -n "not __fish_seen_subcommand_from cache"

View File

@@ -75,7 +75,7 @@ _{{PROJECT_EXECUTABLE}}_main() {
;;
style)
_values -s , 'style' auto full plain changes header grid rule numbers snip
_values -s , 'style' auto full plain changes header header-filename header-filesize grid rule numbers snip
;;
esac
}

View File

@@ -146,7 +146,8 @@ Configure which elements (line numbers, file headers, grid borders, Git modifica
of components to display (e.g. 'numbers,changes,grid') or a pre\-defined style ('full').
To set a default style, add the '\-\-style=".."' option to the configuration file or
export the BAT_STYLE environment variable (e.g.: export BAT_STYLE=".."). Possible
values: *full*, auto, plain, changes, header, grid, rule, numbers, snip.
values: *full*, auto, plain, changes, header, header-filename, header-filesize, grid,
rule, numbers, snip.
.HP
\fB\-r\fR, \fB\-\-line\-range\fR <N:M>...
.IP

BIN
assets/syntaxes.bin vendored

Binary file not shown.

View File

@@ -181,7 +181,7 @@ man 2 select
## インストール
[![Packaging status](https://repology.org/badge/vertical-allrepos/bat.svg)](https://repology.org/project/bat/versions)
[![Packaging status](https://repology.org/badge/vertical-allrepos/bat-cat.svg)](https://repology.org/project/bat-cat/versions)
### On Ubuntu (`apt` を使用)
*... や他のDebianベースのLinuxディストリビューション*

View File

@@ -160,7 +160,7 @@ man 2 select
## Установка
[![Packaging status](https://repology.org/badge/vertical-allrepos/bat.svg)](https://repology.org/project/bat/versions)
[![Packaging status](https://repology.org/badge/vertical-allrepos/bat-cat.svg)](https://repology.org/project/bat-cat/versions)
### Ubuntu (с помощью `apt`)
*... и другие дистрибутивы основанные на Debian.*

View File

@@ -1,16 +1,5 @@
# Release checklist
## Dependencies
See this page for a good overview: https://deps.rs/repo/github/sharkdp/bat
- [ ] Optional: update dependencies with `cargo update`. This is also done by
dependabot, so it is not strictly necessary.
- [ ] Install [cargo-outdated](https://crates.io/crates/cargo-outdated). Check
for outdated dependencies with `cargo outdated --root-deps-only` and
decide for each of them whether we want to (manually) upgrade. This will
require changes to `Cargo.toml`.
## Version bump
- [ ] Update version in `Cargo.toml`. Run `cargo build` to update `Cargo.lock`.
@@ -24,7 +13,7 @@ See this page for a good overview: https://deps.rs/repo/github/sharkdp/bat
## Update syntaxes and themes (build assets)
- [ ] Install the latest master version (`cargo install -f --path .`) and make
- [ ] Install the latest master version (`cargo clean && cargo install -f --path .`) and make
sure that it is available on the `PATH` (`bat --version` should show the
new version).
- [ ] Run `assets/create.sh` and check in the binary asset files.
@@ -32,7 +21,7 @@ See this page for a good overview: https://deps.rs/repo/github/sharkdp/bat
## Documentation
- [ ] Review the `-h` and `--help` texts
- [ ] Review the `man` page
- [ ] Review the `man` page (`man $(fd -HIp target/release/build.*out/assets/manual/bat.1) | tee`)
## Pre-release checks

View File

@@ -1,5 +1,7 @@
## Sponsors
`bat` development is sponsored by many individuals and companies. Thank you very much!
Please note, that being sponsored does not affect the individuality of the `bat`
project or affect the maintainers' actions in any way.
We remain impartial and continue to assess pull requests solely on merit - the

1
rustfmt.toml Normal file
View File

@@ -0,0 +1 @@
# Defaults are used

View File

@@ -463,6 +463,10 @@ impl<'a> Printer for InteractivePrinter<'a> {
let highlight_this_line =
self.config.highlighted_lines.0.check(line_number) == RangeCheckResult::InRange;
if highlight_this_line && self.config.theme == "ansi" {
self.ansi_style.update("^[4m");
}
let background_color = self
.background_color_highlight
.filter(|_| highlight_this_line);
@@ -649,6 +653,11 @@ impl<'a> Printer for InteractivePrinter<'a> {
writeln!(handle)?;
}
if highlight_this_line && self.config.theme == "ansi" {
self.ansi_style.update("^[24m");
write!(handle, "\x1B[24m")?;
}
Ok(())
}
}

View File

@@ -122,8 +122,22 @@ impl<'a> SyntaxMapping<'a> {
.insert("*.hook", MappingTarget::MapTo("INI"))
.unwrap();
if let Some(xdg_config_home) = std::env::var_os("XDG_CONFIG_HOME") {
let git_config_path = Path::new(&xdg_config_home).join("git");
// Global git config files rooted in `$XDG_CONFIG_HOME/git/` or `$HOME/.config/git/`
// See e.g. https://git-scm.com/docs/git-config#FILES
if let Some(xdg_config_home) =
std::env::var_os("XDG_CONFIG_HOME").filter(|val| !val.is_empty())
{
insert_git_config_global(&mut mapping, &xdg_config_home);
}
if let Some(default_config_home) = std::env::var_os("HOME")
.filter(|val| !val.is_empty())
.map(|home| Path::new(&home).join(".config"))
{
insert_git_config_global(&mut mapping, &default_config_home);
}
fn insert_git_config_global(mapping: &mut SyntaxMapping, config_home: impl AsRef<Path>) {
let git_config_path = config_home.as_ref().join("git");
mapping
.insert(

3
tests/examples/git/.config/git/config vendored Normal file
View File

@@ -0,0 +1,3 @@
[user]
email = foo@bar.net
name = foobar

3
tests/examples/git/.gitconfig vendored Normal file
View File

@@ -0,0 +1,3 @@
[user]
email = foo@bar.net
name = foobar

View File

@@ -1117,7 +1117,9 @@ Single Line
────────────────────────────────────────────────────────────────────────────────
",
)
.stderr("\x1b[33m[bat warning]\x1b[0m: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.\n");
.stderr(
"\x1b[33m[bat warning]\x1b[0m: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.\n",
);
}
#[cfg(target_os = "linux")]
@@ -1290,6 +1292,25 @@ fn grid_for_file_without_newline() {
.stderr("");
}
// For ANSI theme, use underscore as a highlighter
#[test]
fn ansi_highlight_underline() {
bat()
.arg("--paging=never")
.arg("--color=never")
.arg("--terminal-width=80")
.arg("--wrap=never")
.arg("--decorations=always")
.arg("--theme=ansi")
.arg("--style=plain")
.arg("--highlight-line=1")
.write_stdin("Ansi Underscore Test\nAnother Line")
.assert()
.success()
.stdout("\x1B[4mAnsi Underscore Test\n\x1B[24mAnother Line")
.stderr("");
}
// Ensure that ANSI passthrough is emitted properly for both wrapping and non-wrapping printer.
#[test]
fn ansi_passthrough_emit() {
@@ -1340,6 +1361,45 @@ fn ignored_suffix_arg() {
.stderr("");
}
#[test]
fn all_global_git_config_locations_syntax_mapping_work() {
let fake_home = Path::new(EXAMPLES_DIR).join("git").canonicalize().unwrap();
let expected = "\u{1b}[38;5;231m[\u{1b}[0m\u{1b}[38;5;149muser\u{1b}[0m\u{1b}[38;5;231m]\u{1b}[0m
\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;231memail\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;203m=\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186mfoo@bar.net\u{1b}[0m
\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;231mname\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;203m=\u{1b}[0m\u{1b}[38;5;231m \u{1b}[0m\u{1b}[38;5;186mfoobar\u{1b}[0m
";
bat()
.env("XDG_CONFIG_HOME", fake_home.join(".config").as_os_str())
.arg("-f")
.arg("-p")
.arg("git/.config/git/config")
.assert()
.success()
.stdout(expected)
.stderr("");
bat()
.env("HOME", fake_home.as_os_str())
.arg("-f")
.arg("-p")
.arg("git/.config/git/config")
.assert()
.success()
.stdout(expected)
.stderr("");
bat()
.env("HOME", fake_home.as_os_str())
.arg("-f")
.arg("-p")
.arg("git/.gitconfig")
.assert()
.success()
.stdout(expected)
.stderr("");
}
#[test]
fn acknowledgements() {
bat()

View File

@@ -0,0 +1,60 @@
import "../imported-file" ;
# With Comments !
def weird($a; $b; $c):
 [ $a, $b, $c ] | transpose | reduce .[][] as $item (
 [];
 . + $item.property
 )
;
. | weird (.a; .b; .c) |
(
if (. | contains("never") ) then
 "Why yes"
else
 12.23
end
) as $never |
{
 hello,
 why: "because",
 hello: ( weird | ascii_upcase ),
 format_eg: ( . | @json "My json string \( . | this | part | just | white | ascii_upcase | transpose)" ),
 never: $never,
 "literal_key": literal_value,
 "this": 12.1e12,
 "part": "almost"
 "like": [
 12,
 2
 "json"
 {
 "quite": {
 similar: "but not quite"
 }
 }
 ],
} | (
 
 # And with very basic brace matching
 
 # Invalid End
 ] 
 
 # Other invalid ends
 ( [ } ] )
 # A "valid" sequence
 ( [ { key: () , other_key:( [ [] [[]] ] ), gaga } ] )
 # A "invalid" sequence
 ( [ { key: () , other_key:( [ [] [[] ] ), gaga } ] )
 "A string\n whith escaped characters \" because we can"
)

25
tests/syntax-tests/source/JQ/LICENSE.md vendored Normal file
View File

@@ -0,0 +1,25 @@
The `sample.jq` file was taken from [SublimeJQ] under the following license:
[SublimeJQ]: https://github.com/zogwarg/SublimeJQ
MIT License
Copyright (c) 2017 Thomas Buick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

60
tests/syntax-tests/source/JQ/sample.jq vendored Normal file
View File

@@ -0,0 +1,60 @@
import "../imported-file" ;
# With Comments !
def weird($a; $b; $c):
[ $a, $b, $c ] | transpose | reduce .[][] as $item (
[];
. + $item.property
)
;
. | weird (.a; .b; .c) |
(
if (. | contains("never") ) then
"Why yes"
else
12.23
end
) as $never |
{
hello,
why: "because",
hello: ( weird | ascii_upcase ),
format_eg: ( . | @json "My json string \( . | this | part | just | white | ascii_upcase | transpose)" ),
never: $never,
"literal_key": literal_value,
"this": 12.1e12,
"part": "almost"
"like": [
12,
2
"json"
{
"quite": {
similar: "but not quite"
}
}
],
} | (
# And with very basic brace matching
# Invalid End
]
# Other invalid ends
( [ } ] )
# A "valid" sequence
( [ { key: () , other_key:( [ [] [[]] ] ), gaga } ] )
# A "invalid" sequence
( [ { key: () , other_key:( [ [] [[] ] ), gaga } ] )
"A string\n whith escaped characters \" because we can"
)