bat简介 -- 带语法高亮和git集成的cat

let cat be colorful -- use bat to replace cat

简介

bat的目的很是简单,就是一个带有语法高亮的cat,他们的选项基本都同样,另外它还会自动获取你git的信息,可以标出目前文件和git缓存区文件的区别,这样你一眼就能够看出你的修改。git

安装

先安装RUST, 而后github

# Recursive clone to retrieve all submodules
git clone --recursive https://github.com/sharkdp/bat

# Build (debug version)
cd bat
cargo build --release

# copy bat to your $PATH
cp target/release/bat /home/harriszh/app/bin

用法

显示单文件: bat README.md
显示多文件: bat src/*.rs
从标准输入读取,显式描述语言: yaml2json .travis.yml | json_pp | bat -l jsonshell

cat类似:json

bat > note.md  # 快速建立文件

bat header.md content.md footer.md > document.md

bat -n main.rs  # 显示行数, 默认行为

bat f - g  # 依次显示文件f, stdin, 文件g

配置

设置主题

#bat
export BAT_THEME=GitHub
export BAT_CONFIG_DIR="$(bat cache --config-dir)"
# use the following command to parse new syntaxed files into a binary cache
#bat cache --init
# use the following command to go back the default setting
#bat cache --clear

能够用bat --list-themes来获得目前可用的主题
能够用bat --theme=TwoDark来定义此次使用的主题
能够用bat --style=numbers,changes来定义输出缓存

添加新的主题

BAT_CONFIG_DIR="$(bat cache --config-dir)"

mkdir -p "$BAT_CONFIG_DIR/themes"
cd "$BAT_CONFIG_DIR/themes"

# Download a theme in '.tmTheme' format, for example:
git clone https://github.com/greggb/sublime-snazzy

# Update the binary cache
bat cache --init

添加新的语法高亮文件

bat使用的是syntest这个语法库,syntest使用的是sublime的语法格式app

BAT_CONFIG_DIR="$(bat cache --config-dir)"

mkdir -p "$BAT_CONFIG_DIR/syntaxes"
cd "$BAT_CONFIG_DIR/syntaxes"

# Put new '.sublime-syntax' language definition files
# in this folder (or its subdirectories), for example:
git clone https://github.com/tellnobody1/sublime-purescript-syntax

bat cache --init

如何下载systemverilog语法文件

能够从这里来下载
firefox_2018-09-13_00-20-47ui

实际要下的是这两个文件
firefox_2018-09-13_00-22-38
没有办法直接下载,因此打开文件,而后复制粘贴下来
放到~/.config/bat/syntaxes里, 而后更新bat的语法库this

bat cache --init

能够用bat --list-languages来确认spa

效果以下:
vmplayer_2018-09-15_15-45-45firefox

与git的集成效果

bat会查看当前文件和git缓存里文件的修改,效果以下
vmplayer_2018-09-15_15-53-12如上图69,70行就是新增长的行

相关文章
相关标签/搜索