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

Bat is an advanced version of Cat that integrates syntax highlighting and Git version management. Bat has all the functions of CAT, and has integrated code highlighting and Git version management tools. It will automatically page-out long files and not print them all at once like CAT.

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 check whether a message is displayed.

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 to be highlighted in the file, you can use the -l parameter to specify the language, for example, bat./test.json -l json to specify the json mode to be highlighted in the file. In short, it’s relatively simple to use, not complicated at all.

conclusion

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

Hope you enjoy this post and share it. If you have better command, welcome message exchange.