linux:bat

bat - シンタックスハイライトとGitとの連携機能付きの cat(1) クローン

カラーテーマの一覧🤔

$ 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

fzf をインストールしてテーマをプレビューする🤔

$ bat --list-themes | fzf --preview="bat --theme={} --color=always ~/.bashrc"

bat_fzf_001

公式: 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
〜省略〜

  • linux/bat.txt
  • 最終更新: 2024/04/22 07:54
  • by ともやん