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行就是新增長的行

相關文章
相關標籤/搜索