As a programmer often use the command line to process some files, such as the common: Git, vim, and some commands in different languages. In so many commands, I believe you must have used the cat command to view the content of the file, but this command can only display the text, which does not help us to read and understand the content, especially when the content of the file is code, it looks particularly painful. This article will introduce a better alternative to cat, which is the bat command. (Not the script in Windows.)

Bat is introduced

batIs a syntax highlighting andGitThe integration of thecatAdvanced edition, in other words,batcatAnd has integrated code highlighting, and Git version management tools, and will automatically pagination long files, not likecatPrint it all at once. Let’s take a look at the effect picture:

Bat installation

The installation method is also super simple, the specific installation is as follows:

  • On Linux
git clone https://aur.archlinux.org/bat.git
cd bat
makepkg -si
Copy the code
  • On MACOS
brew install bat
Copy the code

After the installation is complete, enter bat-help to see if a message is displayed to confirm whether the installation is successful.

Bat use

Similar to cat, the bat file is followed by the file, or it can be opened at the same time, but the result is displayed one after another. If you open a git managed file, you will see the added and removed parts of the file, as shown below:If you need to specify the language highlighted in the file, you can use the -l argument to specify the language, for example:

bat ./test.json -l json
Copy the code

If you do not specify json mode, it will be automatically recognized by default. In short, it’s relatively simple to use, not complicated at all.

conclusion

Alias cat= ‘bat’ alias cat= ‘bat’ alias cat= bat