BATCAT(1)
β¨ BATCAT(1) β¨
okay so welcome to the BATCAT(1) page, part of General Commands Manual, and bestie you're gonna love her π she's basically cat but with a glow-up. grab a snack, this one's long.
πΈ NAME πΈ
batcat β a cat(1) clone with syntax highlighting and Git integration. π
iconic.
π¦ USAGE π¦
batcat [OPTIONS] [FILE]...
batcat cache [CACHE-OPTIONS] [--build|--clear]
π DESCRIPTION π
kay so. batcat prints the syntax-highlighted content of whatever pile of FILEs you hand her, straight to the terminal. and if you hand her no FILE at all β or if FILE is literally - β she reads from standard input instead. no notes. π«Ά
she supports a large number of programming and markup languages, like genuinely a lot, and she also talks to git(1) so she can show you modifications with respect to the git index. oh and she automatically pipes her output through a pager (by default: less). she's polite like that.
here's the important part, bestie: whenever batcat's output goes to a non-interactive terminal β meaning it's being piped into another process or into a file β she switches into drop-in replacement mode for cat(1) and falls back to printing the plain file contents. no colors, no drama. unless you explicitly asked for a style, in which case she does what you said. periodt.
π OPTIONS π
General remarks first, because rules are rules: command-line options like -l/--language that take values can be written as --language value, --language=value, -l value, or -lvalue. all four, all valid, pick your vibe. β¨
-A,--show-allβ shows non-printable characters like space, tab, or newline. if you wanna control how wide those tab-placeholders are, go see--tabs. π--nonprintable-notation <notation>β tells her how to display non-printable characters when you're using--show-all.
possible values:
caretβ use character sequences like^G,^J,^@,..to identify non-printable characters π€unicodeβ use special Unicode code points to identify non-printable characters π
--binary <behavior>β how should she treat binary content? choose wisely.
possible values:
no-printingβ do not print any binary content. this is the default. πas-textβ treat binary content as normal text. bold move, bestie π
--completion <SHELL>β shows shell completion for a certain shell. possible values:bash,fish,zsh,ps1. β¨-p,--plainβ only show plain style, no decorations. this is an alias for--style=plain. and if you use-ptwice (-pp), it also disables automatic paging β which is an alias for--style=plain --paging=never. βοΈ-l,--language <language>β explicitly set the language for syntax highlighting. you can give it a name (likeC++orLaTeX) or a possible file extension (likecpp,hpp, ormd). wanna see all the supported language names and file extensions? run--list-languages. π-H,--highlight-line <N:M>...β highlights the line ranges you specify with a different background color. so 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
yes the + relative thing is real and yes it's a slay β¨
--file-name <name>...β specify the name to display for a file. super useful when you're piping data tobatcatfrom STDIN and she has no idea what the filename is. heads up: the file name you provide is also used for syntax detection. two birds. π¦-d,--diffβ only show lines that have been added/removed/modified with respect to the Git index. wanna control how much context you see around those? use--diff-context=N. π--diff-context <N>...β includeNlines of context around the added/removed/modified lines when you're using--diff.--tabs <T>β set the tab width toTspaces. use a width of0to pass tabs through directly. π--wrap <mode>β specify the text-wrapping mode (auto,never,character). and you can pair it with the--terminal-widthoption to control the output width too.-S,--chop-long-linesβ truncate all lines longer than screen width. this is an alias for--wrap=never. choppy but make it fashion βοΈ--terminal-width <width>β explicitly set the width of the terminal instead of letting her figure it out automatically. if you prefix the value with+or-, it gets 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 auto mode only enables colors if an interactive terminal is detected. possible values: auto,never,always. π--italic-text <when>β specify when to use ANSI sequences for italic text in the output. possible values:always, never. (never is the default, she's just chillin) π--decorations <when>β specify when to use the decorations that have been specified via--style. the auto mode only enables decorations if an interactive terminal is detected, while thealwaysmode will show decorations even when piping output. possible values: auto,never,always. π-f,--force-colorizationβ alias for--decorations=always --color=always. this is useful when the output ofbatcatis piped to another program but you still want to keep the colorization/decorations. main character energy, refuse to be boring π--paging <when>β specify when to use the pager. wanna disable the pager? use--paging=neveror its alias,-P. wanna disable it permanently? setBAT_PAGERto an empty string. and to control which pager gets used, see the--pageroption. possible values: auto,never,always.--pager <command>β determines which pager is used. this option overrides thePAGERandBAT_PAGERenvironment variables. the default pager isless. if you provide--pager=builtin, she uses the built-inminuspager. to control when the pager is used, see the--pagingoption. example:--pager "less -RF". π«Ά
note: by default, if the pager is set toless(and no command-line options are specified),batwill pass the following command line options to the pager:-R/--RAW-CONTROL-CHARS,-F/--quit-if-one-screenand-X/--no-init. the last option (-X) is only used forlessversions older than 530. the-Roption is needed to interpret ANSI colors correctly. the second option (-F) instructs less to exit immediately if the output size is smaller than the vertical size of the terminal β which is convenient for small files because you do not have to press q to quit the pager. the third option (-X) is needed to fix a bug with the--quit-if-one-screenfeature in old versions ofless. unfortunately, it also breaks mouse-wheel support inless. if you want to enable mouse-wheel scrolling on older versions ofless, you can pass just-R(like in the example above β this will disable the quit-if-one-screen feature). for less 530 or newer, it should work out of the box. β¨
-m,--map-syntax <glob-pattern:syntax-name>...β 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*.buildfiles with the Python syntax, use-m '*.build:Python'. to highlight files named.myignorewith the Git Ignore syntax, use-m '.myignore:Git Ignore'. heads up though: the right-hand side is the name of the syntax, not a file extension. important distinction, bestie π--ignored-suffix <ignored-suffix>β ignore extension. for example:bat --ignored-suffix ".dev" my_file.json.devwill use JSON syntax, and ignore.dev. π--theme <theme>β set the theme for syntax highlighting. use--list-themesto see all available themes. to set a default theme, add the--theme="..."option to the configuration file, or export theBAT_THEMEenvironment variable (e.g.:export BAT_THEME="..."). πΈ
special values:
auto(default) β picks a dark or light theme depending on the terminal's colors. use--theme-lightand--theme-darkto customize the selected theme.auto:alwaysβ a variation of auto where the terminal's colors are detected even when the output is redirected.auto:system(macOS only) β a variation of auto where the color scheme is detected from the system-wide preference instead.darkβ use the dark theme specified by--theme-dark.lightβ use the light theme specified by--theme-light.
--theme-dark <theme>β sets the theme name for syntax highlighting used when the terminal uses a dark background. to set a default theme, add the--theme-dark="..."option to the configuration file or export theBAT_THEME_DARKenvironment variable (e.g.export BAT_THEME_DARK="..."). note: this option only has an effect when the--themeoption is set toautoordark. π--theme-light <theme>β sets the theme name for syntax highlighting used when the terminal uses a light background. to set a default theme, add the--theme-light="..."option to the configuration file or export theBAT_THEME_LIGHTenvironment variable (e.g.export BAT_THEME_LIGHT="..."). note: this option only has an effect when the--themeoption is set toautoorlight. βοΈ--list-themesβ displays a list of supported themes for syntax highlighting. window shopping, but make it functional ποΈ-s,--squeeze-blankβ squeeze consecutive empty lines into a single empty line. so satisfying honestly π--squeeze-limit <squeeze-limit>β set the maximum number of consecutive empty lines to be printed.--strip-ansi <when>β specify when to strip ANSI escape sequences from the input. theautomode will remove escape sequences unless the syntax highlighting language is plain text. possible values:auto,always, never. π§Ό--style <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 theBAT_STYLEenvironment variable (e.g.:export BAT_STYLE=".."). π
okay so back to the style tea π β when you set styles in more than one place, the nearest set wins, bestie. Priority order, top to bottom:
- the command-line arguments (highest priority, main character energy π)
- the
BAT_STYLEenvironment variable - the configuration file (lowest priority, the chill one in the back)
But wait, there's a plot twist β¨ if a whole set of styles is made up entirely of components prefixed with + or -, it doesn't replace the previous set β it modifies it. It's giving "add on, don't erase" π
By default, these components are already enabled: changes, grid, header-filename, numbers, snip πΈ
Possible values: default, full, auto, plain, changes, header, header-filename, header-filesize, grid, rule, numbers, snip.
-r,--line-range <N:M>...β only print the range of lines you asked for, per file, no extras π 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 30:+10
prints lines 30 to 40
-L,--list-languagesβ shows you a list of every language supported for syntax highlighting π¦ (so you can see what batcat actually knows how to colorize).-u,--unbufferedβ so this one exists purely for POSIX-compliance reasons ('u'stands for'unbuffered', iykyk). But plot twist: the output is always unbuffered anyway, so this option is just... ignored. It's a decoration β¨--no-custom-assetsβ don't load custom assets, periodt π ββοΈ--config-dirβ shows bat's configuration directory π--cache-dirβ shows bat's cache directory ποΈ--diagnosticβ shows diagnostic info, which you need when you're filing a bug report π (devs love this one fr fr)--acknowledgementsβ shows acknowledgements π«Ά (credit where credit is due)--set-terminal-titleβ sets the terminal title to the filenames when you're using a pager π·οΈ-h,--helpβ prints this help message, bestie π-V,--versionβ shows version information β
β¨ POSITIONAL ARGUMENTS β¨
<FILE>...β the files to print and concatenate, obviously ππ want to read from standard input instead? Use a dash ('-') or just don't give any argument at all π
π SUBCOMMANDS π
cacheβ modify the syntax-definition and theme cache π
ποΈ FILES ποΈ
batcat can also be customized with a configuration file π and where that file lives? depends on your operating system, bestie. To get the default path for your system, call:
batcat --config-file
Or, if you wanna be extra, you can use the BAT_CONFIG_PATH environment variable to point batcat at a non-default location for the config file πΈ
To generate a default configuration file, call:
batcat --generate-config-file
These are the related options:
--config-fileβ show the path to the configuration file π--generate-config-fileβ generates a default configuration file β¨--no-configβ do not use the configuration file π
π§ ADDING CUSTOM LANGUAGES π§
batcat supports Sublime Text .sublime-syntax language files, which means you can add extra languages to your local installation like the icon you are π Here's the whole vibe: drop the .sublime-syntax language files into $(batcat --config-dir)/syntaxes and then run batcat cache --build.
Example:
mkdir -p "$(batcat --config-dir)/syntaxes"
cd "$(batcat --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
# And then build the cache.
batcat cache --build
Once the cache is built, the new language will show up in batcat --list-languages π And if you ever want to remove the custom languages, you can clear the cache with batcat cache --clear π§Ή
π ADDING CUSTOM THEMES π
Same energy as custom languages, honestly π
batcat supports Sublime Text .tmTheme themes too. You install them into $(batcat --config-dir)/themes, and they get added to the cache with batcat cache --build β¨
π₯ INPUT PREPROCESSOR π₯
Much like less(1) does, batcat supports input preprocessors via the LESSOPEN and LESSCLOSE environment variables π«Ά And on top of that, batcat tries its absolute best to be as compatible with less's preprocessor implementation as possible.
To use the preprocessor, call:
batcat --lessopen
Or you can enable the preprocessor by default by adding the '--lessopen' option to the configuration file πΈ
And if you need to temporarily disable the preprocessor when it's on by default, call:
batcat --no-lessopen
These are the related options:
--lessopenβ enable the$LESSOPENpreprocessor π--no-lessopenβ disable the$LESSOPENpreprocessor if it's enabled (and yes, this overrides--lessopen) π
For more info, go read the "INPUT PREPROCESSOR" section of less(1) π
π MORE INFORMATION π
For more information and up-to-date documentation, go visit the batcat repo, bestie: https://github.com/sharkdp/bat
and that's a wrap on the BATCAT(1) page, gorgeous π«Ά you just read the whole thing, no skimming, no cap β iconic behavior, truly ate and left no crumbs ππ
go highlight something pretty β¨
π¦ where this page comes from
- ubuntu stonking: bat 0.26.1+ds-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms