Highly integrated and fast cloning, a powerful tool for developers! BAT

Highly integrated and fast cloning, a powerful tool for developers! BAT

2022-10-19 0 1,243
Resource Number 46100 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

The BAT recommended in this issue is similar to cat (1), with many features such as git integration and syntax highlighting.

Highly integrated and fast cloning, a powerful tool for developers! BAT插图

major function

syntax on

BAT provides high language syntax for programming language highlighting and annotation:

Highly integrated and fast cloning, a powerful tool for developers! BAT插图1

Git Integration

BAT can retrieve file modifications from Git and display them in the sidebar (see figure below):

Highly integrated and fast cloning, a powerful tool for developers! BAT插图2

Non printable display printing visualization

Adding the – A/– show all parameter can include non printable characters in the file:

Highly integrated and fast cloning, a powerful tool for developers! BAT插图3

Collate

BAT will generally output the content displayed within a larger screen display range to a paging device (pager, such as less).

You can add the — paging=never parameter when calling to bat without using a paginator (just like cat). If you want to use the bat alias for cat, you can add alias cat=’bat — paging=never ‘in the shell configuration file (shell configuration).

Intelligent output

BAT can pipeline while setting paginator options, allowing non exemplary clients to use the current file BAT or pipeline image, and output the content to the venue through the pipeline at once without considering the parameter content.

How to use

View a file in the terminal

> bat README.md

Display multiple files

> bat src/*.rs

Read streaming annotations from STDIN, add syntax highlighting to the input content based on the first item, and automatically recognize whether the language of the input content is correct, usually using the shebang tag on the content line, #! Bin/sh as

> curl -s https://sh.rustup.rs | bat

Language explicitly specifies the input of STDIN

> yaml2json .travis.yml | json_pp | bat -l json

Display non printable characters

> bat -A /etc/hosts

Similar to cat

bat > note.md  # Create an empty file

bat header.md content.md footer.md > document.md

bat -n main.rs  # Only display line numbers

bat f - g  # Output f, followed by the standard input stream, and finally g

tool

fzf

You can use bat as the fzf previewer. This requires loading the — color=always option after bat, as well as adding the — line range option to limit the number of large files.

fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}'

Find or fd

You can use the – exec option of find to search for results using bat:

find … -exec bat {} +

Alternatively, when using fd, add the – X/– exec batch option:

fd … -X bat

ripgrep

Batgrep can also display search results for ripgrep.

batgrep needle src/

tail -f

When paired with tail-f, bat can continuously monitor file content and highlight it using different syntax.

tail -f /var/log/pacman.log | bat --paging=never -l log

git

Of course, bat can also accept output from git show and directly customize syntax highlighting (syntax also needs to be manually specified):

git show v0.6.0:src/main.rs | bat -l rs

man

Bat also requires setting the output MANPAGER environment variable for man:

export MANPAGER="sh -c 'col -bx | bat -l man -p'"
man 2 select

Ubuntu (using apt)

If you are unable to use one installation method or need to use the latest version of bat, you can download the latest. deb package from the release page and install it using the following method:

sudo dpkg -i bat_0.18.3_amd64.deb  # adapt version number and architecture

Arch Linux

You can install the bat package from the official source using the following command:

pacman -S bat

Funtoo Linux

You can install the bat package from dev kit:

emerge sys-apps/bat

Gentoo Linux

You can use the following command to install the bat package from the official source:

emerge sys-apps/bat

customize

Grammar Highlighting Theme

Using the syntax bat — list topics, also — theme=TwoDark, highlight using the specified theme as TwoDark. You can configure the theme selection by setting the BAT_THEME environment. Add export BAT_THEME=”TwoDark” to the shell startup script (shell startup file) to achieve a permanent effect. Or use bat files

To view the display of all themes in one file, you can use the following command (fzf needs to be installed):

bat --list-themes | fzf --preview="bat --theme={} --color=always /path/to/file"

By default, bat can add excellent effects on black theme backgrounds. If your terminal uses a bright background, you can add GitHub or OneHalfLight to the theme to add custom themes.

8 themes

Bat comes with three 8-bit color themes:

  • Ansi is suitable for most scenarios. It uses 3-bit colors: black, red, yellow, blue, magenta, indigo, cyan, and white.
  • Base16 is designed specifically for Base16 terminals. It uses 4-bit color (free 3-bit color). Make according to the Base16 styling guide.
  • Base16-25 should be designed for base16 shell. It replaces some bright colors with 8-bit colors. Please do not directly use the theme if your 256 color terminal is using base16 shell.

These themes have unique colors, but some real themes do not have:

  • All terminal tools support 3-bit color.
  • Meet the terminal theme.
  • Visually more coordinated with other terminal tools.

Add new language and grammar

When the existing bat does not support your own language or syntax, you can add it.

Bat uses the syntax library to support syntax highlighting, which utilizes Sublime Text.subrime-syntax syntax files and themes.

When you find a grammar file, follow the following steps:

1. Create a directory containing syntax description files:

mkdir -p "$(bat --config-dir)/syntaxes"
cd "$(bat --config-dir)/syntaxes"

# Put new '.sublime-syntax' language definition files
# in this folder (or its subdirectories), for example:
git clone https://github.com/tellnobody1/sublime-purescript-syntax

2. Function call instructions to convert files into cache:

bat cache --build

3. bat — list languages: Finally, check if the new syntax has been successfully imported. To roll back to the initial state, use:

bat cache --clear

Use custom paginator

BAT uses a paginator defined by the PAGER environment variable, and if not defined, uses less. Bat provides the BAT-PAGER environment variable to specifically select a paginator for bat (prioritizing PAGER).

Note: When PAGER is set to more or most, bat can replace less to ensure color support.

export BAT_PAGER="less -RF"

In addition to using environment variables to change the paginator used by bat, the — pager parameter can also be provided in the configuration file.

Note: The parameter parameters need to be specified in the ANSI standard color description: bat/- R, — RAW-Control-CHARS/- F, and — quit if one screen/- X (– no int only applies to other interpretations). When the terminal is vertically sized, it can be played normally on one screen. Support mouse scroll wheel cancellation function.

-R-Flessq-X-Fless-Rquit-if-one-screen。

configuration file

bat --config-file

You can also use BATVNet PATH to bat configuration files that specify custom locations:

export BAT_CONFIG_PATH="/path/to/bat.conf"

Using the — generate config file parameter to call bat will generate a default bat configuration file at the specified location:

bat --generate-config-file

—END—

Open Source Protocol: LICENSE-2.0

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code Highly integrated and fast cloning, a powerful tool for developers! BAT https://ictcoder.com/kyym/highly-integrated-and-fast-cloning-a-powerful-tool-for-developers.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service