├── .gitignore ├── assets ├── en.md └── readme.md ├── doc ├── alternatives.md ├── alternatives.zh.md └── logo-header.svg ├── en.md └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | fork 4 | source -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/logo-header.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /en.md: -------------------------------------------------------------------------------- 1 |
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 | -------------------------------------------------------------------------------- /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 | 48 | 49 | ### 目录 50 | 51 | 52 | 53 | 54 | 55 | - [语法高亮显示](#%E8%AF%AD%E6%B3%95%E9%AB%98%E4%BA%AE%E6%98%BE%E7%A4%BA) 56 | - [Git集成](#git%E9%9B%86%E6%88%90) 57 | - [自动分页](#%E8%87%AA%E5%8A%A8%E5%88%86%E9%A1%B5) 58 | - [文件串联](#%E6%96%87%E4%BB%B6%E4%B8%B2%E8%81%94) 59 | - [如何使用](#%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8) 60 | - [安装](#%E5%AE%89%E8%A3%85) 61 | - [Ubuntu](#ubuntu) 62 | - [Arch Linux](#arch-linux) 63 | - [Void Linux](#void-linux) 64 | - [FreeBSD](#freebsd) 65 | - [macOS](#macos) 66 | - [二进制文件](#%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%96%87%E4%BB%B6) 67 | - [源项目](#%E6%BA%90%E9%A1%B9%E7%9B%AE) 68 | - [定制](#%E5%AE%9A%E5%88%B6) 69 | - [高亮主题](#%E9%AB%98%E4%BA%AE%E4%B8%BB%E9%A2%98) 70 | - [输出风格](#%E8%BE%93%E5%87%BA%E9%A3%8E%E6%A0%BC) 71 | - [添加新语法/语言定义](#%E6%B7%BB%E5%8A%A0%E6%96%B0%E8%AF%AD%E6%B3%95%E8%AF%AD%E8%A8%80%E5%AE%9A%E4%B9%89) 72 | - [添加新主题](#%E6%B7%BB%E5%8A%A0%E6%96%B0%E4%B8%BB%E9%A2%98) 73 | - [使用不同的页面方式](#%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%90%8C%E7%9A%84%E9%A1%B5%E9%9D%A2%E6%96%B9%E5%BC%8F) 74 | - [故障排除](#%E6%95%85%E9%9A%9C%E6%8E%92%E9%99%A4) 75 | - [终端和颜色](#%E7%BB%88%E7%AB%AF%E5%92%8C%E9%A2%9C%E8%89%B2) 76 | - [开发](#%E5%BC%80%E5%8F%91) 77 | - [项目目标和替代方案](#%E9%A1%B9%E7%9B%AE%E7%9B%AE%E6%A0%87%E5%92%8C%E6%9B%BF%E4%BB%A3%E6%96%B9%E6%A1%88) 78 | 79 | 80 | 81 | ### 语法高亮显示 82 | 83 | `bat`支持大量编程和`mark**`语言的语法高亮显示: 84 | 85 |  86 | 87 | ### Git集成 88 | 89 | `bat`与`git`沟通,显示关于修改的索引 (参见左侧栏) : 90 | 91 |  92 | 93 | ### 自动分页 94 | 95 | 如果输出对于一个屏幕来说太大,`bat`可以`less`控制自己的输出管道,. 96 | 97 | ### 文件串联 98 | 99 | 哦..你也可以用它来串联文件 :wink: . 每当`bat`检测到非交互式终端,它将回退到打印普通文件内容. 100 | 101 | ## 如何使用 102 | 103 | 在终端上显示单个文件 104 | 105 | ```bash 106 | > bat README.md 107 | ``` 108 | 109 | 一次显示多个文件 110 | 111 | ```bash 112 | > bat src/*.rs 113 | ``` 114 | 115 | 从stdin读取,指定明确语言 116 | 117 | ```bash 118 | > yaml2json .travis.yml | json_pp | bat -l json 119 | ``` 120 | 121 | ```bash 122 | > curl -s https://raw.githubusercontent.com/sharkdp/bat/master/src/main.rs | bat -l rs 123 | ``` 124 | 125 | 作为`cat`的替代品: 126 | 127 | ```bash 128 | bat > note.md # 快速 创建一个新文件 129 | 130 | bat header.md content.md footer.md > document.md 131 | 132 | bat -n main.rs # 展示行数 (only) 133 | 134 | bat f - g # 先输出 'f', 之后是 stdin, 之后是 'g'. 135 | ``` 136 | 137 | ## 安装 138 | 139 | ### Ubuntu 140 | 141 | *一些和其他基于Debian的Linux发行版.* 142 | 143 | 从[releases页面](https://github.com/sharkdp/bat/releases),下载最新的`.deb`包裹,并通过以下方式安装: 144 | 145 | ```bash 146 | sudo dpkg -i bat_0.6.0_amd64.deb # adapt version number and architecture 147 | ``` 148 | 149 | ### Arch Linux 150 | 151 | 你可以安装[该`bat`包](https://www.archlinux.org/packages/community/x86_64/bat/),官方来源: 152 | 153 | ```bash 154 | pacman -S bat 155 | ``` 156 | 157 | ### Void Linux 158 | 159 | 你可以通过xbps-install安装`bat`: 160 | 161 | xbps-install -S bat 162 | 163 | ### FreeBSD 164 | 165 | 您可以用pkg安装预编译的[`bat`包](https://www.freshports.org/textproc/bat): 166 | 167 | ```bash 168 | pkg install bat 169 | ``` 170 | 171 | 或者在FreeBSD上,自己构建它: 172 | 173 | ```bash 174 | cd /usr/ports/textproc/bat 175 | make install 176 | ``` 177 | 178 | ### macOS 179 | 180 | 你可以安装`bat`,通过[brew](http://braumeister.org/formula/bat): 181 | 182 | ```bash 183 | brew install bat 184 | ``` 185 | 186 | ### 二进制文件 187 | 188 | 看[releases页面](https://github.com/sharkdp/bat/releases),其中预建版本的`bat`,有许多不同的架构, 要看清楚啦. 189 | 190 | ### 源项目 191 | 192 | 如果你想建立`bat`的源代码,您需要`Rust 1.26或更高版本`. 然后你可以使用`cargo`建立一切: 193 | 194 | ```bash 195 | cargo install bat 196 | ``` 197 | 198 | 在macOS上,您可能必须安装`cmake` (`brew install cmake`) 以便构建一些依赖项. 199 | 200 | ## 定制 201 | 202 | ### 高亮主题 203 | 204 | 使用`bat --list-themes`获取语法高亮显示的所有可用主题的列表. 选择`TwoDark`主题,运行`bat`带`--theme=TwoDark`选项,或设置`BAT_THEME`环境变量为`TwoDark`. 在你的shell启动文件中使用`export BAT_THEME="TwoDark"`,使更改永久化. 205 | 206 | ### 输出风格 207 | 208 | 你可以使用`--style`这个外观的选项,控制`bat`输出. 您可以使用`--style=numbers,changes`例如,仅显示Git更改和行号 ,但没有网格和文件头. 209 | 210 | ### 添加新语法/语言定义 211 | 212 | `bat`使用优秀的语法高亮的库[`syntect`](https://github.com/trishume/syntect/). `syntect`可以阅读任何[Sublime Text的`.sublime-syntax`文件](https://www.sublimetext.com/docs/3/syntax.html)和主题. 要添加新语法定义,请执行以下操作. 213 | 214 | 使用语法定义文件创建一个文件夹: 215 | 216 | ```bash 217 | BAT_CONFIG_DIR="$(bat cache --config-dir)" 218 | 219 | mkdir -p "$BAT_CONFIG_DIR/syntaxes" 220 | cd "$BAT_CONFIG_DIR/syntaxes" 221 | 222 | # 把 '.sublime-syntax' 语言定义文件 放到 223 | # 这个syntaxes目录 (or 它的 子目录), 例如: 224 | git clone https://github.com/tellnobody1/sublime-purescript-syntax 225 | ``` 226 | 227 | 现在使用以下命令将这些文件解析为二进制缓存: 228 | 229 | ```bash 230 | bat cache --init 231 | ``` 232 | 233 | 最后,使用`bat --list-languages`检查新语言是否可用. 234 | 235 | 如果您想要返回默认设置,请使用: 236 | 237 | ```bash 238 | bat cache --clear 239 | ``` 240 | 241 | ### 添加新主题 242 | 243 | 这与我们添加新语法定义的方式非常相似. 244 | 245 | 首先,使用新语法高亮显示主题创建一个文件夹: 246 | 247 | ```bash 248 | BAT_CONFIG_DIR="$(bat cache --config-dir)" 249 | 250 | mkdir -p "$BAT_CONFIG_DIR/themes" 251 | cd "$BAT_CONFIG_DIR/themes" 252 | 253 | # 下载一个主题是 '.tmTheme' 格式, for example: 254 | git clone https://github.com/greggb/sublime-snazzy 255 | 256 | # 更新缓存 257 | bat cache --init 258 | ``` 259 | 260 | 最后,使用`bat --list-themes`检查新主题是否可用. 261 | 262 | ### 使用不同的页面方式 263 | 264 | `bat`使用在`PAGER`环境变量中,指定的页面方式. 如果未设置此变量,`less`就是默认使用的. 如果要使用其他页面方式,可以修改`PAGER`变量或设置`BAT_PAGER`环境变量,以覆盖在`PAGER`中指定的内容. 如果要将命令行参数传递给页面方式,则需要创建一个 小的shell脚本 作为包装器,例如: 265 | 266 | ```bash 267 | #!/bin/bash 268 | 269 | less --tabs 4 -RF "$@" 270 | ``` 271 | 272 | ## 故障排除 273 | 274 | ### 终端和颜色 275 | 276 | `bat`控制终端*有*还是*没有*真彩色支持. 但是,语法高亮主题中的颜色未针对8位颜色进行优化,因此强烈建议您使用具有24位真彩色支持的终端 (`terminator`,`konsole`,`iTerm2`,...) . 看看[本文](https://gist.github.com/XVilka/8346728)了解更多详情和完整的支持truecolor的终端列表. 277 | 278 | 确保你的truecolor终端,设置了`COLORTERM`变量到`truecolor`或者`24bit`. 除此以外,`bat`将无法确定是否支持24位转义序列 (并回退到8位颜色) . 279 | 280 | ## 开发 281 | 282 | ```bash 283 | # Recursive clone to retrieve all submodules 284 | git clone --recursive https://github.com/sharkdp/bat 285 | 286 | # Build (debug version) 287 | cd bat 288 | cargo build 289 | 290 | # Run unit tests and integration tests 291 | cargo test 292 | 293 | # Install (release version) 294 | cargo install 295 | 296 | # 构建 bat 二进制文件, 若修改了的语法和主题 297 | bash assets/create.sh 298 | cargo install -f 299 | ``` 300 | 301 | ## 项目目标和替代方案 302 | 303 | `bat`试图实现以下目标: 304 | 305 | - 提供美观,高级的语法高亮 306 | - 与Git集成以显示文件修改 307 | - 是 (POSIX)`cat` 的直接替代品 308 | - 提供用户友好的命令行界面 309 | 310 | 如果你正在寻找类似的程序,有很多选择. 看[这个文件](doc/alternatives.zh.md)进行比较. 311 | --------------------------------------------------------------------------------