目次
文書の過去の版を表示しています。
bat - シンタックスハイライトとGitとの連携機能付きの cat(1) クローン
使い方
ヘルプ
$ bat --help
A cat(1) clone with syntax highlighting and Git integration.
Usage: bat [OPTIONS] [FILE]...
bat <COMMAND>
Arguments:
[FILE]...
File(s) to print / concatenate. Use a dash ('-') or no argument at all to read from
standard input.
Options:
-A, --show-all
Show non-printable characters like space, tab or newline. This option can also be used to
print binary files. Use '--tabs' to control the width of the tab-placeholders.
--nonprintable-notation <notation>
Set notation for non-printable characters.
Possible values:
* unicode (␇, ␊, ␀, ..)
* caret (^G, ^J, ^@, ..)
-p, --plain...
Only show plain style, no decorations. This is an alias for '--style=plain'. When '-p' is
used twice ('-pp'), it also disables automatic paging (alias for '--style=plain
--paging=never').
-l, --language <language>
Explicitly set the language for syntax highlighting. The language can be specified as a
name (like 'C++' or 'LaTeX') or possible file extension (like 'cpp', 'hpp' or 'md'). Use
'--list-languages' to show all supported language names and file extensions.
-H, --highlight-line <N:M>
Highlight the specified line ranges with a different background color For example:
'--highlight-line 40' highlights line 40
'--highlight-line 30:40' highlights lines 30 to 40
'--highlight-line :40' highlights lines 1 to 40
'--highlight-line 40:' highlights lines 40 to the end of the file
'--highlight-line 30:+10' highlights lines 30 to 40
--file-name <name>
Specify the name to display for a file. Useful when piping data to bat from STDIN when bat
does not otherwise know the filename. Note that the provided file name is also used for
syntax detection.
-d, --diff
Only show lines that have been added/removed/modified with respect to the Git index. Use
--diff-context=N to control how much context you want to see.
--diff-context <N>
Include N lines of context around added/removed/modified lines when using '--diff'.
--tabs <T>
Set the tab width to T spaces. Use a width of 0 to pass tabs through directly
--wrap <mode>
Specify the text-wrapping mode (*auto*, never, character). The '--terminal-width' option
can be used in addition to control the output width.
-S, --chop-long-lines
Truncate all lines longer than screen width. Alias for '--wrap=never'.
--terminal-width <width>
Explicitly set the width of the terminal instead of determining it automatically. If
prefixed with '+' or '-', the value will be treated as an offset to the actual terminal
width. See also: '--wrap'.
-n, --number
Only show line numbers, no other decorations. This is an alias for '--style=numbers'
--color <when>
Specify when to use colored output. The automatic mode only enables colors if an
interactive terminal is detected - colors are automatically disabled if the output goes to
a pipe.
Possible values: *auto*, never, always.
--italic-text <when>
Specify when to use ANSI sequences for italic text in the output. Possible values: always,
*never*.
--decorations <when>
Specify when to use the decorations that have been specified via '--style'. The automatic
mode only enables decorations if an interactive terminal is detected. Possible values:
*auto*, never, always.
-f, --force-colorization
Alias for '--decorations=always --color=always'. This is useful if the output of bat is
piped to another program, but you want to keep the colorization/decorations.
--paging <when>
Specify when to use the pager. To disable the pager, use --paging=never' or its
alias,'-P'. To disable the pager permanently, set BAT_PAGING to 'never'. To control which
pager is used, see the '--pager' option. Possible values: *auto*, never, always.
--pager <command>
Determine which pager is used. This option will override the PAGER and BAT_PAGER
environment variables. The default pager is 'less'. To control when the pager is used, see
the '--paging' option. Example: '--pager "less -RF"'.
-m, --map-syntax <glob:syntax>
Map a glob pattern to an existing syntax name. The glob pattern is matched on the full
path and the filename. For example, to highlight *.build files with the Python syntax, use
-m '*.build:Python'. To highlight files named '.myignore' with the Git Ignore syntax, use
-m '.myignore:Git Ignore'. Note that the right-hand side is the *name* of the syntax, not
a file extension.
--ignored-suffix <ignored-suffix>
Ignore extension. For example:
'bat --ignored-suffix ".dev" my_file.json.dev' will use JSON syntax, and ignore '.dev'
--theme <theme>
Set the theme for syntax highlighting. Use '--list-themes' to see all available themes. To
set a default theme, add the '--theme="..."' option to the configuration file or export
the BAT_THEME environment variable (e.g.: export BAT_THEME="...").
--list-themes
Display a list of supported themes for syntax highlighting.
--style <components>
Configure which elements (line numbers, file headers, grid borders, Git modifications, ..)
to display in addition to the file contents. The argument is a comma-separated list of
components to display (e.g. 'numbers,changes,grid') or a pre-defined style ('full'). To
set a default style, add the '--style=".."' option to the configuration file or export the
BAT_STYLE environment variable (e.g.: export BAT_STYLE="..").
Possible values:
* default: enables recommended style components (default).
* full: enables all available components.
* auto: same as 'default', unless the output is piped.
* plain: disables all available components.
* changes: show Git modification markers.
* header: alias for 'header-filename'.
* header-filename: show filenames before the content.
* header-filesize: show file sizes before the content.
* grid: vertical/horizontal lines to separate side bar
and the header from the content.
* rule: horizontal lines to delimit files.
* numbers: show line numbers in the side bar.
* snip: draw separation lines between distinct line ranges.
-r, --line-range <N:M>
Only print the specified range of lines for each file. For example:
'--line-range 30:40' prints lines 30 to 40
'--line-range :40' prints lines 1 to 40
'--line-range 40:' prints lines 40 to the end of the file
'--line-range 40' only prints line 40
'--line-range 30:+10' prints lines 30 to 40
-L, --list-languages
Display a list of supported languages for syntax highlighting.
-u, --unbuffered
This option exists for POSIX-compliance reasons ('u' is for 'unbuffered'). The output is
always unbuffered - this option is simply ignored.
--diagnostic
Show diagnostic information for bug reports.
--acknowledgements
Show acknowledgements.
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
You can use 'bat cache' to customize syntaxes and themes. See 'bat cache --help' for more
information
カラーテーマの一覧🤔
$ bat --list-themes
Theme: 1337
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Coldark-Cold
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Coldark-Dark
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: DarkNeon
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Dracula
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: GitHub
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Monokai Extended
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Monokai Extended Bright
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Monokai Extended Light
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Monokai Extended Origin
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Nord
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: OneHalfDark
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: OneHalfLight
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Solarized (dark)
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Solarized (light)
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Sublime Snazzy
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: TwoDark
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: Visual Studio Dark+
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: ansi
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: base16
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: base16-256
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: gruvbox-dark
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: gruvbox-light
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Theme: zenburn
// Output the square of a number.
fn print_square(num: f64) {
let result = f64::powf(num, 2.0);
println!("The square of {:.2} is {:.2}.", num, result);
}
Further themes can be installed to '/home/tomoyan/.config/bat/themes', and are added to the cache with `bat cache --build`. For more information, see:
https://github.com/sharkdp/bat#adding-new-themes
サポート言語の一覧🤔
$ bat --list-languages
ActionScript as
Ada adb, ads, gpr
Apache Conf envvars, htaccess, HTACCESS, htgroups, HTGROUPS, htpasswd, HTPASSWD, .htaccess,
.HTACCESS, .htgroups, .HTGROUPS, .htpasswd, .HTPASSWD, /etc/apache2/**/*.conf,
/etc/apache2/sites-*/**/*, httpd.conf
AppleScript applescript, script editor
ARM Assembly s, S
AsciiDoc (Asciidoctor) adoc, ad, asciidoc
ASP asa
Assembly (x86_64) yasm, nasm, asm, inc, mac
Authorized Keys authorized_keys, pub, authorized_keys2
AWK awk
Batch File bat, cmd
BibTeX bib
Bourne Again Shell (bash) sh, bash, zsh, ash, .bash_aliases, .bash_completions, .bash_functions,
.bash_login, .bash_logout, .bash_profile, .bash_variables, .bashrc, .profile,
.textmate_init, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, PKGBUILD, ebuild,
eclass, **/bat/config, /etc/profile, os-release, *.ksh
C c
C# cs, csx
C++ cpp, cc, cp, cxx, c++, h, hh, hpp, hxx, h++, inl, ipp, *.h
Cabal cabal
Clojure clj, cljc, cljs, edn
CMake CMakeLists.txt, cmake
CMake C Header h.in
CMake C++ Header hh.in, hpp.in, hxx.in, h++.in
CMakeCache CMakeCache.txt
CoffeeScript coffee, Cakefile, coffee.erb, cson
Comma Separated Values csv, tsv
Command Help cmd-help, help
CpuInfo cpuinfo
Crontab tab, crontab, cron.d
Crystal cr
CSS css, css.erb, css.liquid
D d, di
Dart dart
Diff diff, patch
Dockerfile Dockerfile, dockerfile, .Dockerfile, Containerfile
DotENV .env, .env.dist, .env.local, .env.sample, .env.example, .env.template, .env.test,
.env.test.local, .env.testing, .env.dev, .env.development, .env.development.local,
.env.prod, .env.production, .env.production.local, .env.dusk.local, .env.staging,
.env.default, .env.defaults, .envrc, .flaskenv, env, env.example, env.sample,
env.template
Elixir ex, exs
Elm elm
Email eml, msg, mbx, mboxz, /var/spool/mail/*, /var/mail/*
Erlang erl, hrl, Emakefile, emakefile, escript
F# fs, fsi, fsx, *.fs
Fish fish
Fortran (Fixed Form) f, F, f77, F77, for, FOR, fpp, FPP
Fortran (Modern) f90, F90, f95, F95, f03, F03, f08, F08
Fortran Namelist namelist
fstab fstab, crypttab, mtab
Git Attributes attributes, gitattributes, .gitattributes, /home/tomoyan/.config/git/attributes
Git Commit COMMIT_EDITMSG, MERGE_MSG, TAG_EDITMSG
Git Config gitconfig, .gitconfig, .gitmodules, /home/tomoyan/.config/git/config
Git Ignore exclude, gitignore, .gitignore, /home/tomoyan/.config/git/ignore
Git Link .git
Git Log gitlog
Git Mailmap .mailmap, mailmap
Git Rebase Todo git-rebase-todo
GLSL vs, gs, vsh, fsh, gsh, vshader, fshader, gshader, vert, frag, geom, tesc, tese,
comp, glsl, mesh, task, rgen, rint, rahit, rchit, rmiss, rcall
gnuplot gp, gpl, gnuplot, gnu, plot, plt
Go go
GraphQL graphql, graphqls, gql
Graphviz (DOT) dot, DOT, gv
Groff/troff groff, troff, 1, 2, 3, 4, 5, 6, 7, 8, 9
Groovy groovy, gvy, gradle, Jenkinsfile
group group
Haskell hs
Highlight non-printables show-nonprintable
hosts hosts
HTML html, htm, shtml, xhtml
HTML (ASP) asp
HTML (EEx) html.eex, html.leex
HTML (Erlang) yaws
HTML (Jinja2) htm.j2, html.j2, xhtml.j2, xml.j2
HTML (Rails) rails, rhtml, erb, html.erb
HTML (Tcl) adp
HTML (Twig) twig, html.twig
HTTP Request and Response http
INI ini, INI, inf, INF, reg, REG, lng, cfg, CFG, desktop, url, URL, .editorconfig,
.coveragerc, .pylintrc, .gitlint, .hgrc, hgrc, **/systemd/**/*.conf,
**/systemd/**/*.example, *.automount, *.device, *.dnssd, *.link, *.mount,
*.netdev, *.network, *.nspawn, *.path, *.service, *.scope, *.slice, *.socket,
*.swap, *.target, *.timer, *.hook
Java java, bsh
Java Properties properties
Java Server Page (JSP) jsp
JavaScript htc
JavaScript (Babel) js, mjs, jsx, babel, es6, cjs, *.pac
JavaScript (Rails) js.erb
Jinja2 j2, jinja2, jinja
JQ jq
JSON json, sublime-settings, sublime-menu, sublime-keymap, sublime-mousemap,
sublime-theme, sublime-build, sublime-project, sublime-completions,
sublime-commands, sublime-macro, sublime-color-scheme, ipynb, Pipfile.lock,
*.jsonl, *.sarif
jsonnet jsonnet, libsonnet, libjsonnet
Julia jl
Known Hosts known_hosts, known_hosts.old
Kotlin kt, kts
LaTeX tex, ltx
Lean lean
Less less, css.less
Lisp lisp, cl, clisp, l, mud, el, scm, ss, lsp, fasl
Literate Haskell lhs
LiveScript ls, Slakefile, ls.erb
LLVM ll
log log
Lua lua, *.nse
Makefile make, GNUmakefile, makefile, Makefile, makefile.am, Makefile.am, makefile.in,
Makefile.in, OCamlMakefile, mak, mk
Manpage man
Markdown md, mdown, markdown, markdn
MATLAB matlab
MediaWiki mediawiki, wikipedia, wiki
MemInfo meminfo
NAnt Build File build
nginx conf.erb, nginx.conf, mime.types, fastcgi_params, scgi_params, uwsgi_params,
/etc/nginx/**/*.conf, /etc/nginx/sites-*/**/*, nginx.conf, mime.types
Nim nim, nims, nimble
Ninja ninja
Nix nix
NSIS nsi, nsh, bnsi, bnsh, nsdinc
Objective-C m
Objective-C++ mm
OCaml ml, mli
OCamllex mll
OCamlyacc mly
orgmode org
Pascal pas, p, dpr
passwd passwd
Perl pl, pc, pm, pmc, pod, t
PHP php, php3, php4, php5, php7, phps, phpt, phtml
Plain Text txt
PowerShell ps1, psm1, psd1
Protocol Buffer proto, protodevel
Protocol Buffer (TEXT) pb.txt, proto.text, textpb, pbtxt, prototxt
Puppet pp, epp
PureScript purs
Python py, py3, pyw, pyi, pyx, pyx.in, pxd, pxd.in, pxi, pxi.in, rpy, cpy, SConstruct,
Sconstruct, sconstruct, SConscript, gyp, gypi, Snakefile, vpy, wscript, bazel,
bzl
QML qml, qmlproject
R R, r, Rprofile
Racket rkt
Rd (R Documentation) rd
Rego rego
Regular Expression re
Requirements.txt requirements.txt, requirements.in, pip
resolv resolv.conf
reStructuredText rst, rest
Robot Framework robot, resource
Ruby rb, Appfile, Appraisals, Berksfile, Brewfile, capfile, cgi, Cheffile, config.ru,
Deliverfile, Fastfile, fcgi, Gemfile, gemspec, Guardfile, irbrc, jbuilder,
Podfile, podspec, prawn, rabl, rake, Rakefile, Rantfile, rbx, rjs, ruby.rail,
Scanfile, simplecov, Snapfile, thor, Thorfile, Vagrantfile
Ruby Haml haml
Ruby on Rails rxml, builder
Ruby Slim slim, skim
Rust rs, *.ron
Salt State (SLS) sls
Sass sass
Scala scala, sbt, sc
SCSS scss
SML sml, cm, sig
Solidity sol
SQL sql, ddl, dml
SQL (Rails) erbsql, sql.erb
SSH Config ssh_config, **/.ssh/config
SSHD Config sshd_config
Strace strace
Stylus styl, stylus
Svelte svlt, svelte
Swift swift
syslog syslog
SystemVerilog sv, svh, vh
Tcl tcl
Terraform tf, tfvars, hcl
TeX sty, cls
Textile textile
Todo.txt todo.txt, done.txt
TOML toml, tml, Cargo.lock, Gopkg.lock, Pipfile, pdm.lock, poetry.lock
TypeScript ts, mts, cts
TypeScriptReact tsx
varlink varlink
Verilog v, V
VimHelp vimhelp
VimL vim, vimrc, gvimrc, .vimrc, .gvimrc, _vimrc, _gvimrc
Vue Component vue
Vyper vy
WGSL wgsl
XML xml, xsd, xslt, tld, dtml, rng, rss, opml, svg, xaml
YAML yaml, yml, sublime-syntax, .clang-format, fish_history
Zig zig
bat + fzf
fzf をインストールしてテーマをプレビューする🤔
設定
公式: Adding or changing file type associations - sharkdp/bat: A cat(1) clone with wings. 翻訳
デフォルトでは以下の場所に config を置く🤔
$ bat --config-dir
/home/tomoyan/.config/bat
$ bat --config-file
/home/tomoyan/.config/bat/config
初期状態ではディレクトリが存在しないので、作成して config ファイルを編集する🤔
$ mkdir -p $(bat --config-dir) $ nano $(bat --config-file)
# Use C++ syntax for Arduino .ino files --map-syntax "*.ino:C++" # Use ".gitignore"-style highlighting for ".ignore" files --map-syntax ".ignore:Git Ignore" # Use Bourne Again Shell (bash) syntax for .commonshrc files --map-syntax ".commonshrc:Bourne Again Shell (bash)"
Or
$ bat --generate-config-file
Success! Config file written to /home/tomoyan/.config/bat/config
$ bat $(bat --config-file)
───────┬──────────────────────────────────────────────────────────────────────────────────────────────────────
│ File: /home/tomoyan/.config/bat/config
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ # This is `bat`s configuration file. Each line either contains a comment or
2 │ # a command-line option that you want to pass to `bat` by default. You can
3 │ # run `bat --help` to get a list of all possible configuration options.
4 │
5 │ # Specify desired highlighting theme (e.g. "TwoDark"). Run `bat --list-themes`
6 │ # for a list of all available themes
7 │ #--theme="TwoDark"
8 │
9 │ # Enable this to use italic text on the terminal. This is not supported on all
10 │ # terminal emulators (like tmux, by default):
11 │ #--italic-text=always
12 │
13 │ # Uncomment the following line to disable automatic paging:
14 │ #--paging=never
15 │
16 │ # Uncomment the following line if you are using less version >= 551 and want to
17 │ # enable mouse scrolling support in `bat` when running inside tmux. This might
18 │ # disable text selection, unless you press shift.
19 │ #--pager="less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse"
20 │
21 │ # Syntax mappings: map a certain filename pattern to a language.
22 │ # Example 1: use the C++ syntax for Arduino .ino files
23 │ # Example 2: Use ".gitignore"-style highlighting for ".ignore" files
24 │ #--map-syntax "*.ino:C++"
25 │ #--map-syntax ".ignore:Git Ignore"
───────┴──────────────────────────────────────────────────────────────────────────────────────────────────────
pager を使用しない、枠線が必要ない場合は、さらに設定を追加する🤔
$ echo '--paging=never' >> $(bat --config-file) $ echo '--style=numbers' >> $(bat --config-file) $ bat $(bat --config-file)
1 # Use C++ syntax for Arduino .ino files 2 --map-syntax "*.ino:C++" 3 4 # Use ".gitignore"-style highlighting for ".ignore" files 5 --map-syntax ".ignore:Git Ignore" 6 7 # Use Bourne Again Shell (bash) syntax for .commonshrc files 8 --map-syntax ".commonshrc:Bourne Again Shell (bash)" 9 10 --paging=never 11 --style=numbers
設定を確認する😉
$ bat --list-languages
〜省略〜
Bourne Again Shell (bash) sh, bash, zsh, ash, .bash_aliases, .bash_completions, .bash_functions,
.bash_login, .bash_logout, .bash_profile, .bash_variables, .bashrc, .profile,
.textmate_init, .zlogin, .zlogout, .zprofile, .zshenv, .zshrc, PKGBUILD, ebuild,
eclass, **/bat/config, /etc/profile, os-release, *.ksh, .commonshrc
〜省略〜
