├── .gitignore ├── assets ├── readme.md └── en.md ├── doc ├── alternatives.zh.md ├── alternatives.md └── logo-header.svg ├── readme.md └── en.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | fork 4 | source -------------------------------------------------------------------------------- /assets/readme.md: -------------------------------------------------------------------------------- 1 | ## BAT 中的语法高亮显示 2 | 3 | `bat`使用[syntect](https://github.com/trishume/syntect)库,以高亮显示源代码. 作为基础,syntect 使用[Sublime Text](https://www.sublimetext.com/)中的语法定义`.sublime-syntax`格式. 4 | 5 | 为了增加新的语法`bat`,请遵循以下步骤: 6 | 7 | 1. 查找给定语言的 Sublime Text 语法,最好是在单独的 Git 存储库中,该存储库可以作为子模块包含 (在`assets/syntaxes`) 8 | 9 | 2. 如果 Sublime Text 语法只能作为`.tmLanguage`文件,以 Sublime Text 打开文件,并将其转换为`.sublime-syntax`文件通过*Tools*>_Developer_>_New Syntax from XXX.tmLanguage..._. 将新文件保存在`assets/syntaxes`文件夹. 10 | 11 | 3. 运行`create.sh`脚本. 它会运行`bat cache --init`解析所有可用的`.sublime-syntax`文件,并将它们序列化为`syntaxes.bin`文件 (在本文件夹中) . 12 | 13 | 4. 重新编译`bat`. 在编译时,`syntaxes.bin`文件将存储在`bat`二进制中. 14 | 15 | ### 故障排除 16 | 17 | 确保本地缓存,不干扰内部存储的语法和主题 (`bat cache --clear`) 18 | 19 | ### 手工修改 20 | 21 | 下列文件在从`.tmLanguage`文件转换后,手动修改: 22 | 23 | - `VimL.sublime-syntax`=>增加`.vimrc`文件类型. 24 | - `Dart.sublime-syntax`=>删除包含的`#regex.dart`, 25 | -------------------------------------------------------------------------------- /assets/en.md: -------------------------------------------------------------------------------- 1 | ## Syntax Highlighting in bat 2 | 3 | `bat` uses the [syntect](https://github.com/trishume/syntect) library to highlight source 4 | code. As a basis, syntect uses [Sublime Text](https://www.sublimetext.com/) syntax definitions 5 | in the `.sublime-syntax` format. 6 | 7 | In order to add new syntaxes to `bat`, follow these steps: 8 | 9 | 1. Find a Sublime Text syntax for the given language, preferably in a separate Git repository 10 | which can be included as a submodule (under `assets/syntaxes`). 11 | 12 | 2. If the Sublime Text syntax is only available as a `.tmLanguage` file, open the file in 13 | Sublime Text and convert it to a `.sublime-syntax` file via *Tools* -> *Developer* -> 14 | *New Syntax from XXX.tmLanguage...*. Save the new file in the `assets/syntaxes` folder. 15 | 16 | 3. Run the `create.sh` script. It calls `bat cache --init` to parse all available 17 | `.sublime-syntax` files and serialize them to a `syntaxes.bin` file (in this folder). 18 | 19 | 4. Re-compile `bat`. At compilation time, the `syntaxes.bin` file will be stored inside the 20 | `bat` binary. 21 | 22 | ### Troubleshooting 23 | 24 | Make sure that the local cache does not interfere with the internally stored syntaxes and 25 | themes (`bat cache --clear`). 26 | 27 | ### Manual modifications 28 | 29 | The following files have been manually modified after converting from a `.tmLanguage` file: 30 | 31 | * `VimL.sublime-syntax` => added `.vimrc` file type. 32 | * `Dart.sublime-syntax` => removed `#regex.dart` include, 33 | -------------------------------------------------------------------------------- /doc/alternatives.zh.md: -------------------------------------------------------------------------------- 1 | 2 | #替代品 3 | 4 | 下表格尝试概述*与`bat`相似的观点*,即我们只比较与`bat`相关的类别. 其中一些项目有完全不同的目标,如果你不是在寻找像`bat`这样的程序,这种比较可能不适合你. 5 | 6 | | | bat | [pygments](http://pygments.org/) | [highlight](http://www.andre-simon.de/doku/highlight/highlight.php) | [ccat](https://github.com/jingweno/ccat) | [source-highlight](https://www.gnu.org/software/src-highlite/) | [hicat](https://github.com/rstacruz/hicat) | [coderay](https://github.com/rubychan/coderay) | [rouge](https://github.com/jneen/rouge) | 7 | | -------------------------------------------- | ------------------------------------------------------------------ | -------------------------------- | ------------------------------------------------------------------- | ---------------------------------------- | -------------------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------- | --------------------------------------- | 8 | | 深入 `cat` 的替代 | :heavy_check_mark: [\*](https://github.com/sharkdp/bat/issues/134) | :x: | :x: | (:heavy_check_mark:) | :x: | :x: [\*](https://github.com/rstacruz/hicat/issues/6) | :x: | :x: | 9 | | Git 集成 | :heavy_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | 10 | | 自动 分页 | :heavy_check_mark: | :x: | :x: | :x: | :x: | :heavy_check_mark: | :x: | :x: | 11 | | 语言 (大约) | 60 | 300 | 200 | 7 | 80 | 130 | 30 | 130 | 12 | | 扩展 (语言, 主题) | :heavy_check_mark: | (:heavy_check_mark:) | (:heavy_check_mark:) | :x: | (:heavy_check_mark:) | :x: | :x: | :x: | 13 | | 优化 语法高亮 (e.g. 嵌套语法) | :heavy_check_mark: | :heavy_check_mark: | (:heavy_check_mark:) ? | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 14 | | 执行 时间 [ms] (`jquery-3.3.1.js`) | 624 | 789 | 400 | 80 | 300 | 316 | 157 | 695 | 15 | | 执行 时间 [ms] (`miniz.c`) | 66 | 656 | 26 | 8 | 53 | 141 | 75 | 254 | 16 | | 执行 时间 [ms] \(370 kB XML 文件) | 238 | 487 | 129 | 111 | 110 | 339 | 147 | 359 | 17 | 18 | 如果您认为此表中的某些条目,已过时或错误,请打开 Issues 或 提取请求. 19 | -------------------------------------------------------------------------------- /doc/alternatives.md: -------------------------------------------------------------------------------- 1 | ∏# Alternatives 2 | 3 | The following table tries to give an overview *from `bat`s perspective*, i.e. we only compare 4 | categories which are relevant for `bat`. Some of these projects have completely different goals and 5 | if you are not looking for a program like `bat`, this comparison might not be for you. 6 | 7 | | | bat | [pygments](http://pygments.org/) | [highlight](http://www.andre-simon.de/doku/highlight/highlight.php) | [ccat](https://github.com/jingweno/ccat) | [source-highlight](https://www.gnu.org/software/src-highlite/) | [hicat](https://github.com/rstacruz/hicat) | [coderay](https://github.com/rubychan/coderay) | [rouge](https://github.com/jneen/rouge) | 8 | |----------------------------------------------|---------------------------------------------------------------------|----------------------------------|---------------------------------------------------------------------|------------------------------------------|----------------------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------| 9 | | Drop-in `cat` replacement | :heavy_check_mark: [*](https://github.com/sharkdp/bat/issues/134) | :x: | :x: | (:heavy_check_mark:) | :x: | :x: [*](https://github.com/rstacruz/hicat/issues/6) | :x: | :x: | 10 | | Git integration | :heavy_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | 11 | | Automatic paging | :heavy_check_mark: | :x: | :x: | :x: | :x: | :heavy_check_mark: | :x: | :x: | 12 | | Languages (circa) | 60 | 300 | 200 | 7 | 80 | 130 | 30 | 130 | 13 | | Extensible (languages, themes) | :heavy_check_mark: | (:heavy_check_mark:) | (:heavy_check_mark:) | :x: | (:heavy_check_mark:) | :x: | :x: | :x: | 14 | | Advanced highlighting (e.g. nested syntaxes) | :heavy_check_mark: | :heavy_check_mark: | (:heavy_check_mark:) ? | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | 15 | | Execution time [ms] (`jquery-3.3.1.js`) | 624 | 789 | 400 | 80 | 300 | 316 | 157 | 695 | 16 | | Execution time [ms] (`miniz.c`) | 66 | 656 | 26 | 8 | 53 | 141 | 75 | 254 | 17 | | Execution time [ms] (370 kB XML file) | 238 | 487 | 129 | 111 | 110 | 339 | 147 | 359 | 18 | 19 | If you think that some entries in this table are outdated or wrong, please open a ticket or pull 20 | request. 21 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # bat [![translate-svg]][translate-list] 2 | 3 | [translate-svg]: http://llever.com/translate.svg 4 | [translate-list]: https://github.com/chinanf-boy/chinese-translate-list 5 | 6 | 「 一个`cat(1)`克隆,搭配语法高亮和Git集成。 」 7 | 8 | [中文](./readme.md) | [english](https://github.com/sharkdp/bat) 9 | 10 | 11 | --- 12 | 13 | 14 | ## 更新 ✅ 15 | 16 | 17 | 18 | 19 | 20 | 翻译的原文 | 与日期 | 最新更新 | 更多 21 | ---|---|---|--- 22 | [commit] | ⏰ 2018 8.30 | ![last] | [中文翻译][translate-list] 23 | 24 | [last]: https://img.shields.io/github/last-commit/sharkdp/bat.svg 25 | [commit]: https://github.com/sharkdp/bat/tree/84734eac9d19f90f942e587e7ec7d3aad4cda2c2 26 | 27 | 28 | 29 | - [bat 中的语法高亮显示说明](assets/readme.md) 30 | 31 | ### 贡献 32 | 33 | 欢迎 👏 勘误/校对/更新贡献 😊 [具体贡献请看](https://github.com/chinanf-boy/chinese-translate-list#贡献) 34 | 35 | ## 生活 36 | 37 | [If help, **buy** me coffee —— 营养跟不上了,给我来瓶营养快线吧! 💰](https://github.com/chinanf-boy/live-need-money) 38 | 39 | --- 40 | 41 |
42 |
43 |
44 |
45 |
46 | 一个 cat(1) 克隆与语法高亮和Git集成。.
47 |
2 |
3 |
4 |
5 |
6 | A cat(1) clone with syntax highlighting and Git integration.
7 |
10 | Key Features • 11 | How To Use • 12 | Installation • 13 | Customization • 14 | Project goals, alternatives 15 |
16 | 17 | ### Syntax highlighting 18 | 19 | `bat` supports syntax highlighting for a large number of programming and markup 20 | languages: 21 | 22 |  23 | 24 | ### Git integration 25 | 26 | `bat` communicates with `git` to show modifications with respect to the index 27 | (see left side bar): 28 | 29 |  30 | 31 | ### Automatic paging 32 | 33 | `bat` can pipe its own output to `less` if the output is too large for one screen. 34 | 35 | ### File concatenation 36 | 37 | Oh.. you can also use it to concatenate files :wink:. Whenever 38 | `bat` detects a non-interactive terminal, it will fall back to printing 39 | the plain file contents. 40 | 41 | ## How to use 42 | 43 | Display a single file on the terminal 44 | 45 | ```bash 46 | > bat README.md 47 | ``` 48 | 49 | Display multiple files at once 50 | 51 | ```bash 52 | > bat src/*.rs 53 | ``` 54 | 55 | Read from stdin, explicitly specify the language 56 | 57 | ```bash 58 | > yaml2json .travis.yml | json_pp | bat -l json 59 | ``` 60 | 61 | ```bash 62 | > curl -s https://raw.githubusercontent.com/sharkdp/bat/master/src/main.rs | bat -l rs 63 | ``` 64 | 65 | As a replacement for `cat`: 66 | 67 | ```bash 68 | bat > note.md # quickly create a new file 69 | 70 | bat header.md content.md footer.md > document.md 71 | 72 | bat -n main.rs # show line numbers (only) 73 | 74 | bat f - g # output 'f', then stdin, then 'g'. 75 | ``` 76 | 77 | ## Installation 78 | 79 | ### On Ubuntu 80 | *... and other Debian-based Linux distributions.* 81 | 82 | Download the latest `.deb` package from the [release page](https://github.com/sharkdp/bat/releases) 83 | and install it via: 84 | ``` bash 85 | sudo dpkg -i bat_0.6.0_amd64.deb # adapt version number and architecture 86 | ``` 87 | 88 | ### On Arch Linux 89 | 90 | You can install [the `bat` package](https://www.archlinux.org/packages/community/x86_64/bat/) 91 | from the official sources: 92 | 93 | ```bash 94 | pacman -S bat 95 | ``` 96 | 97 | ### On Void Linux 98 | 99 | You can install `bat` via xbps-install: 100 | ``` 101 | xbps-install -S bat 102 | ``` 103 | 104 | ### On FreeBSD 105 | 106 | You can install a precompiled [`bat` package](https://www.freshports.org/textproc/bat) with pkg: 107 | 108 | ```bash 109 | pkg install bat 110 | ``` 111 | 112 | or build it on your own from the FreeBSD ports: 113 | 114 | ```bash 115 | cd /usr/ports/textproc/bat 116 | make install 117 | ``` 118 | 119 | ### On macOS 120 | 121 | You can install `bat` with [Homebrew](http://braumeister.org/formula/bat): 122 | 123 | ```bash 124 | brew install bat 125 | ``` 126 | 127 | ### From binaries 128 | 129 | Check out the [Release page](https://github.com/sharkdp/bat/releases) for 130 | prebuilt versions of `bat` for many different architectures. 131 | 132 | ### From source 133 | 134 | If you want to build `bat` from source, you need Rust 1.26 or 135 | higher. You can then use `cargo` to build everything: 136 | 137 | ```bash 138 | cargo install bat 139 | ``` 140 | 141 | On macOS, you might have to install `cmake` (`brew install cmake`) in order for 142 | some dependencies to be built. 143 | 144 | ## Customization 145 | 146 | ### Highlighting theme 147 | 148 | Use `bat --list-themes` to get a list of all available themes for syntax 149 | highlighting. 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 152 | make the change permanent. 153 | 154 | ### Output style 155 | 156 | You can use the `--style` option to control the appearance of `bat`s output. 157 | You can use `--style=numbers,changes`, for example, to show only Git changes 158 | and line numbers but no grid and no file header. 159 | 160 | ### Adding new syntaxes / language definitions 161 | 162 | `bat` uses the excellent [`syntect`](https://github.com/trishume/syntect/) 163 | library for syntax highlighting. `syntect` can read any 164 | [Sublime Text `.sublime-syntax` file](https://www.sublimetext.com/docs/3/syntax.html) 165 | and theme. To add new syntax definitions, do the following. 166 | 167 | Create a folder with syntax definition files: 168 | 169 | ```bash 170 | BAT_CONFIG_DIR="$(bat cache --config-dir)" 171 | 172 | mkdir -p "$BAT_CONFIG_DIR/syntaxes" 173 | cd "$BAT_CONFIG_DIR/syntaxes" 174 | 175 | # Put new '.sublime-syntax' language definition files 176 | # in this folder (or its subdirectories), for example: 177 | git clone https://github.com/tellnobody1/sublime-purescript-syntax 178 | ``` 179 | 180 | Now use the following command to parse these files into a binary cache: 181 | 182 | ```bash 183 | bat cache --init 184 | ``` 185 | 186 | Finally, use `bat --list-languages` to check if the new languages are available. 187 | 188 | If you ever want to go back to the default settings, call: 189 | 190 | ```bash 191 | bat cache --clear 192 | ``` 193 | 194 | ### Adding new themes 195 | 196 | This works very similar to how we add new syntax definitions. 197 | 198 | First, create a folder with the new syntax highlighting themes: 199 | ```bash 200 | BAT_CONFIG_DIR="$(bat cache --config-dir)" 201 | 202 | mkdir -p "$BAT_CONFIG_DIR/themes" 203 | cd "$BAT_CONFIG_DIR/themes" 204 | 205 | # Download a theme in '.tmTheme' format, for example: 206 | git clone https://github.com/greggb/sublime-snazzy 207 | 208 | # Update the binary cache 209 | bat cache --init 210 | ``` 211 | 212 | Finally, use `bat --list-themes` to check if the new themes are available. 213 | 214 | ### Using a different pager 215 | 216 | `bat` uses the pager that is specified in the `PAGER` environment variable. If this variable is not 217 | set, `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 220 | script as a wrapper, for example: 221 | 222 | ```bash 223 | #!/bin/bash 224 | 225 | less --tabs 4 -RF "$@" 226 | ``` 227 | 228 | ## Troubleshooting 229 | 230 | ### Terminals & colors 231 | 232 | `bat` handles terminals *with* and *without* truecolor support. However, the colors in the syntax 233 | highlighting themes are not optimized for 8-bit colors and it is therefore strongly recommended 234 | that you use a terminal with 24-bit truecolor support (`terminator`, `konsole`, `iTerm2`, ...). 235 | See [this article](https://gist.github.com/XVilka/8346728) for more details and a full list of 236 | terminals with truecolor support. 237 | 238 | Make 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 240 | are supported (and fall back to 8-bit colors). 241 | 242 | ## Development 243 | 244 | ```bash 245 | # Recursive clone to retrieve all submodules 246 | git clone --recursive https://github.com/sharkdp/bat 247 | 248 | # Build (debug version) 249 | cd bat 250 | cargo build 251 | 252 | # Run unit tests and integration tests 253 | cargo test 254 | 255 | # Install (release version) 256 | cargo install 257 | 258 | # Build a bat binary with modified syntaxes and themes 259 | bash assets/create.sh 260 | cargo install -f 261 | ``` 262 | 263 | ## Project goals and alternatives 264 | 265 | `bat` tries to achieve the following goals: 266 | 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 271 | 272 | There are a lot of alternatives, if you are looking for similar programs. See 273 | [this document](doc/alternatives.md) for a comparison. 274 | -------------------------------------------------------------------------------- /doc/logo-header.svg: -------------------------------------------------------------------------------- 1 | 2 | --------------------------------------------------------------------------------