Met het Linux ‘cat’ commando kun je snel ASCII files tonen of aan elkaar knopen. Het heeft een aantal opties om de output te veranderen, maar deze zijn vrij eenvoudig.
Met de tool ‘bat’ kun je voor de ouptput van ASCII files ‘syntax highlighting’ toevoegen voor veel programmeer en opmaak talen. Het heeft diverse opties om je output nog mooier en/of gemakkelijker leesbaar te maken.
Om de ‘bat’ tool te installeren gebruik je het commando:
apt get install bat
In Debian zal de tool nu beschikbaar zijn met het commando ‘batcat’ en niet als ‘bat’. Dit is vanwege een mogelijk ‘nameclash’ met een andere pakket. Je kunt dit oplossen door een symbolische link aan te maken op de volgende manier:
mkdir -p ~/.local/bin ln -s /usr/bin/batcat ~/.local/bin/bat
Zie vooral de gibhub pagina van ‘bat’ voor al de mogelijkheden van deze tool.
bat 0.12.1
A cat(1) clone with syntax highlighting and Git integration.
USAGE:
bat [OPTIONS] [FILE]...
bat
OPTIONS:
-l, --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.
-L, --list-languages
Display a list of supported languages for syntax highlighting.
-m, --map-syntax ...
Map a file extension or file name to an existing syntax. For example, to highlight
*.conf files with the INI syntax, use '-m conf:ini'. To highlight files named
'.myignore' with the Git Ignore syntax, use '-m .myignore:gitignore'.
--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
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: *auto*, full, plain, changes, header, grid, numbers, snip.
-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
--pager=never').
-n, --number
Only show line numbers, no other decorations. This is an alias for '--style=numbers'
-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.
-r, --line-range ...
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
-H, --highlight-line ...
Highlight the N-th line with a different background color
--color
Specify when to use colored output. The automatic mode only enables colors if an
interactive terminal is detected. Possible values: *auto*, never, always.
--italic-text
Specify when to use ANSI sequences for italic text in the output. Possible values:
always, *never*.
--decorations
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.
--paging
Specify when to use the pager. To control which pager is used, set the PAGER or
BAT_PAGER environment variables (the latter takes precedence) or use the '--pager'
option. To disable the pager permanently, set BAT_PAGER to an empty string or set
'--paging=never' in the configuration file. Possible values: *auto*, never, always.
--pager
Determine which pager is used. This option will overwrite the PAGER and BAT_PAGER
environment variables. The default pager is 'less'. To disable the pager completely, use
the '--paging' option. Example: '--pager "less -RF"'.
--wrap
Specify the text-wrapping mode (*auto*, never, character). The '--terminal-width' option
can be used in addition to control the output width.
--tabs
Set the tab width to T spaces. Use a width of 0 to pass tabs through directly
-u, --unbuffered
This option exists for POSIX-compliance reasons ('u' is for 'unbuffered'). The output is
always unbuffered - this option is simply ignored.
--terminal-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'.
-h, --help
Print this help message.
-V, --version
Show version information.
ARGS:
...
File(s) to print / concatenate. Use a dash ('-') or no argument at all to read from
standard input.
SUBCOMMANDS:
cache Modify the syntax-definition and theme cache
Hieronder vind je een aantal voorbeelden zodat je een beetje een indruk krijgt van de ‘bat’ tool:
Weet jij ook nog een handig tool voor Debian, dan hoor ik dat graag in de reacties onderaan dit artikel.