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,587
Resource Number 46100 Last Updated 2025-02-24
¥ 0HKD 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/highly-integrated-and-fast-cloning-a-powerful-tool-for-developers/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services