on 3a89486 help sign in
bat/README.md
273 lines 7.4 kB history raw
1<p align="center">
2 <img src="doc/logo-header.svg" alt="bat - a cat clone with wings"><br>
3 <a href="https://travis-ci.org/sharkdp/bat"><img src="https://travis-ci.org/sharkdp/bat.svg?branch=master" alt="Build Status"></a>
4 <img src="https://img.shields.io/crates/l/bat.svg" alt="license">
5 <a href="https://crates.io/crates/bat"><img src="https://img.shields.io/crates/v/bat.svg?colorB=319e8c" alt="Version info"></a><br>
6 A <i>cat(1)</i> clone with syntax highlighting and Git integration.
7</p>
9<p align="center">
10 <a href="#syntax-highlighting">Key Features</a> •
11 <a href="#how-to-use">How To Use</a> •
12 <a href="#installation">Installation</a> •
13 <a href="#customization">Customization</a> •
14 <a href="#project-goals-and-alternatives">Project goals, alternatives</a>
15</p>
17### Syntax highlighting
19`bat` supports syntax highlighting for a large number of programming and markup
20languages:
22![Syntax highlighting example](https://imgur.com/rGsdnDe.png)
24### Git integration
26`bat` communicates with `git` to show modifications with respect to the index
27(see left side bar):
29![Git integration example](https://i.imgur.com/2lSW4RE.png)
31### Automatic paging
33`bat` can pipe its own output to `less` if the output is too large for one screen.
35### File concatenation
37Oh.. you can also use it to concatenate files :wink:. Whenever
38`bat` detects a non-interactive terminal, it will fall back to printing
39the plain file contents.
41## How to use
43Display a single file on the terminal
45```bash
46> bat README.md
47```
49Display multiple files at once
51```bash
52> bat src/*.rs
53```
55Read from stdin, explicitly specify the language
57```bash
58> yaml2json .travis.yml | json_pp | bat -l json
59```
61```bash
62> curl -s https://raw.githubusercontent.com/sharkdp/bat/master/src/main.rs | bat -l rs
63```
65As a replacement for `cat`:
67```bash
68bat > note.md # quickly create a new file
70bat header.md content.md footer.md > document.md
72bat -n main.rs # show line numbers (only)
74bat f - g # output 'f', then stdin, then 'g'.
75```
77## Installation
79### On Ubuntu
80*... and other Debian-based Linux distributions.*
82Download the latest `.deb` package from the [release page](https://github.com/sharkdp/bat/releases)
83and install it via:
84``` bash
85sudo dpkg -i bat_0.6.0_amd64.deb # adapt version number and architecture
86```
88### On Arch Linux
90You can install [the `bat` package](https://www.archlinux.org/packages/community/x86_64/bat/)
91from the official sources:
93```bash
94pacman -S bat
95```
97### On Void Linux
99You can install `bat` via xbps-install:
100```
101xbps-install -S bat
102```
104### On FreeBSD
106You can install a precompiled [`bat` package](https://www.freshports.org/textproc/bat) with pkg:
108```bash
109pkg install bat
110```
112or build it on your own from the FreeBSD ports:
114```bash
115cd /usr/ports/textproc/bat
116make install
117```
119### On macOS
121You can install `bat` with [Homebrew](http://braumeister.org/formula/bat):
123```bash
124brew install bat
125```
127### From binaries
129Check out the [Release page](https://github.com/sharkdp/bat/releases) for
130prebuilt versions of `bat` for many different architectures.
132### From source
134If you want to build `bat` from source, you need Rust 1.26 or
135higher. You can then use `cargo` to build everything:
137```bash
138cargo install bat
139```
141On macOS, you might have to install `cmake` (`brew install cmake`) in order for
142some dependencies to be built.
144## Customization
146### Highlighting theme
148Use `bat --list-themes` to get a list of all available themes for syntax
149highlighting. To select the `TwoDark` theme, call `bat` with the
150`--theme=TwoDark` option or set the `BAT_THEME` environment variable to
151`TwoDark`. Use `export BAT_THEME="TwoDark"` in your shells startup file to
152make the change permanent.
154### Output style
156You can use the `--style` option to control the appearance of `bat`s output.
157You can use `--style=numbers,changes`, for example, to show only Git changes
158and line numbers but no grid and no file header.
160### Adding new syntaxes / language definitions
162`bat` uses the excellent [`syntect`](https://github.com/trishume/syntect/)
163library for syntax highlighting. `syntect` can read any
164[Sublime Text `.sublime-syntax` file](https://www.sublimetext.com/docs/3/syntax.html)
165and theme. To add new syntax definitions, do the following.
167Create a folder with syntax definition files:
169```bash
170BAT_CONFIG_DIR="$(bat cache --config-dir)"
172mkdir -p "$BAT_CONFIG_DIR/syntaxes"
173cd "$BAT_CONFIG_DIR/syntaxes"
175# Put new '.sublime-syntax' language definition files
176# in this folder (or its subdirectories), for example:
177git clone https://github.com/tellnobody1/sublime-purescript-syntax
178```
180Now use the following command to parse these files into a binary cache:
182```bash
183bat cache --init
184```
186Finally, use `bat --list-languages` to check if the new languages are available.
188If you ever want to go back to the default settings, call:
190```bash
191bat cache --clear
192```
194### Adding new themes
196This works very similar to how we add new syntax definitions.
198First, create a folder with the new syntax highlighting themes:
199```bash
200BAT_CONFIG_DIR="$(bat cache --config-dir)"
202mkdir -p "$BAT_CONFIG_DIR/themes"
203cd "$BAT_CONFIG_DIR/themes"
205# Download a theme in '.tmTheme' format, for example:
206git clone https://github.com/greggb/sublime-snazzy
208# Update the binary cache
209bat cache --init
210```
212Finally, use `bat --list-themes` to check if the new themes are available.
214### Using a different pager
216`bat` uses the pager that is specified in the `PAGER` environment variable. If this variable is not
217set, `less` is used by default. If you want to use a different pager, you can either modify the
218`PAGER` variable or set the `BAT_PAGER` environment variable to override what is specified in
219`PAGER`. If you want to pass command-line arguments to the pager, you need to create a small shell
220script as a wrapper, for example:
222```bash
223#!/bin/bash
225less --tabs 4 -RF "$@"
226```
228## Troubleshooting
230### Terminals & colors
232`bat` handles terminals *with* and *without* truecolor support. However, the colors in the syntax
233highlighting themes are not optimized for 8-bit colors and it is therefore strongly recommended
234that you use a terminal with 24-bit truecolor support (`terminator`, `konsole`, `iTerm2`, ...).
235See [this article](https://gist.github.com/XVilka/8346728) for more details and a full list of
236terminals with truecolor support.
238Make sure that your truecolor terminal sets the `COLORTERM` variable to either `truecolor` or
239`24bit`. Otherwise, `bat` will not be able to determine whether or not 24-bit escape sequences
240are supported (and fall back to 8-bit colors).
242## Development
244```bash
245# Recursive clone to retrieve all submodules
246git clone --recursive https://github.com/sharkdp/bat
248# Build (debug version)
249cd bat
250cargo build
252# Run unit tests and integration tests
253cargo test
255# Install (release version)
256cargo install
258# Build a bat binary with modified syntaxes and themes
259bash assets/create.sh
260cargo install -f
261```
263## Project goals and alternatives
265`bat` tries to achieve the following goals:
267- Provide beautiful, advanced syntax highlighting
268- Integrate with Git to show file modifications
269- Be a drop-in replacement for (POSIX) `cat`
270- Offer a user-friendly command-line interface
272There are a lot of alternatives, if you are looking for similar programs. See
273[this document](doc/alternatives.md) for a comparison.