### Direct URL Installation with VCS Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Installs a package directly from a VCS repository. This example uses Git with a specific commit hash. ```requirements.txt pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=da9234ee9982d4bbb3c72346a6de940a148ea686 ``` -------------------------------- ### Bat Configuration File Example Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt A sample configuration file for bat. Lines starting with '#' are comments. This file accepts command-line arguments. ```shell # Example configuration file for bat. # Use --help to see all possible options. --tabs=4 --theme=TwoDark ``` -------------------------------- ### PowerShell Script Example Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt A basic PowerShell script file example. ```powershell assets/syntaxes/02_Extra/PowerShell/examples/test.ps1 ``` -------------------------------- ### Install bat on openSUSE Source: https://github.com/sharkdp/bat/blob/master/README.md Use the zypper package manager to install bat on openSUSE. ```bash zypper install bat ``` -------------------------------- ### Install bat on Windows via Scoop Source: https://github.com/sharkdp/bat/blob/master/README.md Use the scoop command to install bat on Windows. ```bash scoop install bat ``` -------------------------------- ### Install bat on Windows via WinGet Source: https://github.com/sharkdp/bat/blob/master/README.md Use the winget command to install bat on Windows. ```bash winget install sharkdp.bat ``` -------------------------------- ### Install bat on OpenBSD Source: https://github.com/sharkdp/bat/blob/master/README.md Use the pkg_add command to install bat on OpenBSD. ```bash pkg_add bat ``` -------------------------------- ### Java Example with Callouts Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/AsciiDoc/test.adoc Demonstrates a simple Java class with line callouts for explanations. ```java public class Example { // <1> private static boolean isExample = true; // <2> } ``` -------------------------------- ### Installing and Building Custom Syntax Assets Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This sequence of commands demonstrates the process of installing a custom syntax file and then building the custom assets for 'bat' to recognize it. It involves copying the syntax file and running the 'bat cache --build' command. ```shell custom_syntaxes_dir="$( bat --config-dir)/syntaxes" cp -v "tests/BatTestCustomAssets.sublime-syntax" \ "${custom_syntaxes_dir}/BatTestCustomAssets.sublime-syntax" ``` ```shell bat cache --build ``` -------------------------------- ### Install bat from crates.io Source: https://github.com/sharkdp/bat/blob/master/README.md Install bat from crates.io using cargo install. Ensure Rust 1.79.0 or higher is installed. ```bash cargo install --locked bat ``` -------------------------------- ### Example bat configuration file Source: https://github.com/sharkdp/bat/blob/master/README.md Illustrates a sample `bat` configuration file with comments, setting the theme and display styles. ```bash # Set the theme to "TwoDark" --theme="TwoDark" # Show line numbers, Git modifications and file header (but no grid) --style="numbers,changes,header" ``` -------------------------------- ### Basic CMake Project Setup Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/CMake/CMakeLists.txt Initializes a CMake project with a specified version and project details, including languages. ```cmake cmake_minimum_required(VERSION 3.13) project(hello-bat VERSION 0.0.1 LANGUAGES C) ``` -------------------------------- ### Help Subject Wildcard Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Demonstrates using wildcards in the help subject to find related tags. This example searches for any 'z' command. ```vim :help z? ``` -------------------------------- ### Install bat on Fedora Source: https://github.com/sharkdp/bat/blob/master/README.md Use the dnf package manager to install bat on Fedora. ```bash dnf install bat ``` -------------------------------- ### Install Latest Bat Version Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Instructions to install the latest version of Bat, ensuring new syntaxes are included. ```bash - [ ] Go to https://github.com/sharkdp/bat/releases/new to create the new ``` -------------------------------- ### Rust Example: Pretty Printer Library Usage Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Demonstrates basic usage of the bat library for pretty-printing code. This example shows how to import and use the PrettyPrinter struct. ```rust use bat::PrettyPrinter; ``` -------------------------------- ### Install bat on Gentoo Linux Source: https://github.com/sharkdp/bat/blob/master/README.md Use the emerge package manager to install bat on Gentoo Linux. ```bash emerge sys-apps/bat ``` -------------------------------- ### Install bat on FreeBSD Source: https://github.com/sharkdp/bat/blob/master/README.md Use the pkg package manager to install bat on FreeBSD. ```bash pkg install bat ``` -------------------------------- ### Vim Help File Syntax Example Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Demonstrates basic syntax elements in a Vim help file, including punctuation, entity names, and variables. ```vim # <- punctuation.definition.constant.begin #^^^^^^^^^^^^ entity.name.reference.link # ^ punctuation.definition.constant.end VIM REFERENCE MANUAL by Bram Moolenaar # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language ``` -------------------------------- ### Install bat via nix Source: https://github.com/sharkdp/bat/blob/master/README.md Use the nix-env command to install bat using the nix package manager. ```bash nix-env -i bat ``` -------------------------------- ### Rust Example: Simple Cat Clone with Bat Library Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt A basic example of creating a colorized 'cat' command clone using the bat library. It demonstrates integrating bat's pretty-printing capabilities into other command-line tools. ```rust use bat::PrettyPrinter; /// See `src/bin/bat` for the full `bat` application. ``` -------------------------------- ### Install bat on Windows via Chocolatey Source: https://github.com/sharkdp/bat/blob/master/README.md Use the choco command to install bat on Windows. ```bash choco install bat ``` -------------------------------- ### Package from URL Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Installs a package directly from a URL, such as a zip archive on GitHub. The '#egg=click' specifies the package name. ```requirements.txt https://github.com/pallets/click/archive/7.0.zip#egg=click ``` -------------------------------- ### Package from VCS (Git) Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Installs a package from a Git repository using an editable install. The '#egg=MyProject' specifies the package name. ```requirements.txt -e git+git://git.myproject.org/MyProject#egg=MyProject ``` ```requirements.txt -e git://git.myproject.org/MyProject.git@v1.0#egg=MyProject ``` -------------------------------- ### Inline Code Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Markdown/example.md Demonstrates how to format inline code using backticks. ```markdown `fn inline_code() -> String { "inline code".to_string() }` ``` -------------------------------- ### Vim Help Tag Navigation Example Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Shows how to use ':help' followed by ':tag' and ':tselect' within the help window for navigating matches. ```vim It is also possible to first do ":help" and then use ":tag {pattern}" in the help window. The ":tnext" command can then be used to jump to other matches, "tselect" to list matches and choose one. > :help index :tselect /.*mode < ``` -------------------------------- ### Install bat .deb package on Debian-based systems Source: https://github.com/sharkdp/bat/blob/master/README.md Installs a downloaded `.deb` package for `bat`. Adapt the filename to match the version and architecture of the downloaded file. This is useful for installing the latest release. ```bash sudo dpkg -i bat_0.18.3_amd64.deb # adapt version number and architecture ``` -------------------------------- ### Install bat on Alpine Linux Source: https://github.com/sharkdp/bat/blob/master/README.md Use the apk package manager to install bat on Alpine Linux. ```bash apk add bat ``` -------------------------------- ### Install bat on Arch Linux Source: https://github.com/sharkdp/bat/blob/master/README.md Use the pacman package manager to install bat on Arch Linux. ```bash pacman -S bat ``` -------------------------------- ### Package from VCS (Bazaar) Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Installs a package from a Bazaar repository using an editable install. Supports both SSH and HTTPS protocols. ```requirements.txt -e bzr+ssh://user@myproject.org/MyProject/trunk#egg=MyProject ``` ```requirements.txt -e bzr+https://bzr.myproject.org/MyProject/trunk@2019#egg=MyProject ``` -------------------------------- ### Rust Main Function Example Source: https://github.com/sharkdp/bat/blob/master/tests/snapshots/output/full.snapshot.txt A simple main function demonstrating struct instantiation and function calls. ```rust fn main() { let rect1 = Rectangle { width: 30, height: 50 }; println!( "The perimeter of the rectangle is {} pixels.", perimeter(&rect1) ); } ``` -------------------------------- ### Rust Example: Input and Pretty Printer Library Usage Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Shows how to use the bat library with both Input and PrettyPrinter components. This is useful for more advanced customization of the pretty-printing process. ```rust use bat::{Input, PrettyPrinter}; ``` -------------------------------- ### Case-Sensitive Help Grep Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Performs a case-sensitive search across all help files for the word 'Uganda'. ```vim :helpgrep Uganda ``` -------------------------------- ### Build bat from local source Source: https://github.com/sharkdp/bat/blob/master/README.md Build bat from local source code using cargo install. Ensure Rust 1.79.0 or higher is installed. ```bash cargo install --path . --locked ``` -------------------------------- ### Install Bat on Manjaro Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Command to install Bat on Manjaro Linux using pacman. ```bash pacman -S bat ``` -------------------------------- ### Sidebar Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/AsciiDoc/test.adoc Illustrates how to create a sidebar in AsciiDoc. Sidebars are typically used for supplementary information or asides. ```asciidoc **** This will be rendered like a sidebar **** ``` -------------------------------- ### Vim Help Command Completion Example Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Illustrates how to use CTRL-D for command-line completion after ':help subject' and lists potential matches. ```vim # ^^^^^^ markup.underline.link.key after ":help subject" |c_CTRL-D|). If there are several matches, you can have them listed by hitting CTRL-D. Example: > :help cont < ``` -------------------------------- ### Install bat on Ubuntu/Debian using apt Source: https://github.com/sharkdp/bat/blob/master/README.md This command installs the `bat` package using the `apt` package manager on Ubuntu or Debian-based systems. Ensure your system's package list is up-to-date before running. ```bash sudo apt install bat ``` -------------------------------- ### Install bat on macOS or Linux via Homebrew Source: https://github.com/sharkdp/bat/blob/master/README.md Use the brew package manager to install bat on macOS or Linux. ```bash brew install bat ``` -------------------------------- ### Package from VCS (Subversion) Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Installs a package from a Subversion repository using an editable install. The '@2019' specifies a revision. ```requirements.txt -e svn+http://svn.myproject.org/svn/MyProject/trunk@2019#egg=MyProject ``` -------------------------------- ### Rust Example: Advanced Pretty Printer Library Usage Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Illustrates advanced usage of the bat library, including PagingMode and WrappingMode. This allows for fine-grained control over how output is displayed. ```rust use bat::{PagingMode, PrettyPrinter, WrappingMode}; ``` -------------------------------- ### Create and Navigate to Bat Themes Directory Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt These commands create a directory for bat themes and then navigate into it. This is useful for installing custom themes. ```shell mkdir -p "$(bat --config-dir)/themes" cd "$(bat --config-dir)/themes" ``` -------------------------------- ### Package from VCS (Mercurial) Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Installs a package from a Mercurial repository using an editable install. The '@da39a3ee5e6b' specifies a revision. ```requirements.txt -e hg+https://hg.myproject.org/MyProject#egg=MyProject ``` ```requirements.txt -e hg+http://hg.myproject.org/MyProject@da39a3ee5e6b#egg=MyProject ``` -------------------------------- ### Build Bat Binary Source: https://github.com/sharkdp/bat/blob/master/README.md Build a bat binary with modified syntaxes and themes. This involves running a creation script and then installing the package. ```bash bash assets/create.sh cargo install --path . --locked --force ``` -------------------------------- ### Vim Help Subject Syntax Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Shows syntax for specifying a subject with the ':help' command, including wildcard examples and literal tags. ```vim :h[elp] {subject} Like ":help", additionally jump to the tag {subject}. For example: > :help options < ``` ```vim {subject} can include wildcards such as "*", "?" and # ^ punctuation.definition.constant.begin # ^^^^^^^ constant.numeric # ^ punctuation.definition.constant.end "[a-z]": :help z? jump to help for any "z" command :help z. jump to the help for "z." But when a tag exists it is taken literally: :help :? jump to help for ":?" ``` -------------------------------- ### Piping Script Output to Bat Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This example demonstrates piping the output of a script (curl -s https://sh.rustup.rs) to 'bat' for syntax highlighting. This is useful for viewing script output in a more readable format. ```bash curl -s https://sh.rustup.rs | bat ``` -------------------------------- ### Blockquote Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/AsciiDoc/test.adoc Demonstrates how to create a blockquote in AsciiDoc. This is used for quoting text from another source. ```asciidoc ____ This is a random blockquote ____ ``` -------------------------------- ### Case-Insensitive Help Grep Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Performs a case-insensitive search across all help files for the word 'uganda' by appending '\c'. ```vim :helpgrep uganda\c ``` -------------------------------- ### Highlight help messages with bat Source: https://github.com/sharkdp/bat/blob/master/README.md This example demonstrates using `bat` to colorize help text output from commands like `cp --help`. It uses `bat -plhelp` to specify the language as 'help'. ```bash $ cp --help | bat -plhelp ``` -------------------------------- ### Org-mode Table Formula Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/orgmode/test.org Demonstrates Org-mode's table formula syntax for calculations within tables. Use this for dynamic table content. ```orgmode | n | n + 2 | n ^ 2 | |---+-------+-------| | 1 | 3 | 1 | | 2 | 4 | 4 | | 3 | 5 | 9 | #+TBLFM: $2=$1+2::$3=$1*$1 ``` -------------------------------- ### Doctest Block Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/reStructuredText/reference.rst An example of an interactive Python session represented as a doctest block, starting with '>>>' and ending with a blank line. ```python >>> print "This is a doctest block." This is a doctest block. ``` -------------------------------- ### Display a single file with bat Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Use 'bat' to display the contents of a file with syntax highlighting. This is a basic usage example. ```shell > bat README.md ``` -------------------------------- ### Complex Version and Environment Specification Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Requirements.txt/requirements.txt Combines version specifiers, extras, and environment markers. This example specifies a version less than 2 and greater than or equal to 3, conditional on the OS name being 'a'. ```requirements.txt foobar[quux]<2,>=3; os_name=='a' ``` -------------------------------- ### Help Subject Literal Match Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Shows how a literal subject is matched, even if it contains special characters like '?'. ```vim :help z. ``` -------------------------------- ### TOML Syntax Mapping Example Source: https://github.com/sharkdp/bat/blob/master/src/syntax_mapping/builtins/README.md Defines syntax mappings for TOML and YAML files for a hypothetical 'foo-application'. Rules are specified as glob patterns. ```toml # 30-foo-application.toml [mappings] "TOML" = [ # rules for TOML syntax go here "/usr/share/foo-application/toml-config/*.conf", "/etc/foo-application/toml-config/*.conf", ] "YAML" = [ # rules for YAML syntax go here # ... ] ``` -------------------------------- ### Get bat configuration file path Source: https://github.com/sharkdp/bat/blob/master/README.md Prints the default path for the `bat` configuration file on the current system. ```bash bat --config-file ``` -------------------------------- ### Previewing Bat Themes with fzf Source: https://github.com/sharkdp/bat/blob/master/README.md This command allows you to preview available bat themes on a custom file using fzf for interactive selection. Ensure fzf is installed. ```bash bat --list-themes | fzf --preview="bat --theme={} --color=always /path/to/file" ``` -------------------------------- ### Open Help Window Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Opens the help window to display the Vim help file. If a help window is already open, it reuses it. The layout of the new window depends on the current window's size and position. ```vim :h[elp] ``` -------------------------------- ### Setting Custom Configuration and Cache Directories Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt These lines demonstrate how to set environment variables for custom configuration and cache directories using temporary directories. This is useful for testing custom asset installations without affecting the global configuration. ```shell BAT_CONFIG_DIR=$(mktemp -d) export BAT_CONFIG_DIR ``` ```shell BAT_CACHE_PATH=$(mktemp -d) export BAT_CACHE_PATH ``` ```shell BAT_CONFIG_DIR = ${ BAT_CONFIG_DIR} ``` ```shell BAT_CACHE_PATH = ${ BAT_CACHE_PATH} ``` -------------------------------- ### LaTeX Environment Definition (match) Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt LaTeX syntax highlighting rule for matching the start of a 'verbatim' environment, including variations. ```latex - match: '((\\begin)(\{) ((?:[vV]erbatim|alltt)*?)\\})' ``` -------------------------------- ### Vim Help Command Syntax Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Demonstrates the syntax for the ':h' or ':help' command and its associated key link. ```vim *help* ** *:h* *:help* ** *i_* *i_* or #^^^^^ markup.underline.link.key :h[elp] Open a window and display the help file in read-only mode. If there is a help window open already, use that one. Otherwise, if the current window uses the full width of the screen or is at least 80 characters wide, the help window will appear just above the current window. Otherwise the new window is put at the very top. The 'helplang' option is used to select a language, if # ^ punctuation.definition.link.option.begin # ^^^^^^^^ markup.underline.link.option # ^ punctuation.definition.link.option.end the main help file is available in several languages. ``` -------------------------------- ### Vim Help Literal Tag Example Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Demonstrates how to search for help on specific control characters like CTRL-V using literal tag syntax. ```vim Instead of typing ":help CTRL-V" to search for help for CTRL-V you can type: > :help ^V < ``` ```vim This also works together with other characters, for example to find help for CTRL-V in Insert mode: > :help i^V < ``` -------------------------------- ### Search All Help Files Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Searches all Vim help text files for lines matching the specified {pattern}. Jumps to the first match and allows navigation through results using quickfix commands. ```vim :helpg[rep] {pattern}[@xx] ``` -------------------------------- ### Navigate Help Matches Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Illustrates a workflow for navigating help topics: first opening a general help page, then using ':tag' to find specific subjects, and ':tnext' or ':tselect' to manage multiple matches. ```vim :help index :tselect /.*mode ``` -------------------------------- ### Install bat on macOS via MacPorts Source: https://github.com/sharkdp/bat/blob/master/README.md Use the port command to install bat on macOS via MacPorts. ```bash port install bat ``` -------------------------------- ### Open Help in a New Xterm Window Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt This command demonstrates how to open Vim's help documentation in a separate xterm window. ```bash :!xterm -e vim +help & ``` -------------------------------- ### Vim Help Heading Syntax Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Illustrates the syntax for a level 1 heading in Vim help files, using setext style. ```vim #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ punctuation.definition.heading.1.setext 1. Help commands *online-help* #^^^^^^^^^^^^^^^ markup.heading.1.setext ``` -------------------------------- ### Benchmark Script for Code Highlighters Source: https://github.com/sharkdp/bat/blob/master/doc/alternatives.md This bash script benchmarks various code highlighting tools using 'hyperfine'. It requires 'hyperfine' to be installed and sets up commands for 'bat', 'pygmentize', 'highlight', 'ccat', 'source-highlight', 'hicat', 'coderay', 'rouge', and 'clp'. ```bash #!/usr/bin/env bash cd "$(dirname "${BASH_SOURCE[0]}")" || exit if ! command -v hyperfine > /dev/null 2>&1; then echo "'hyperfine' does not seem to be installed." echo "You can get it here: https://github.com/sharkdp/hyperfine" exit 1 fi SRC="test-src/jquery-3.3.1.js" cmd_bat="bat --style=full --color=always --paging=never '$SRC'" cmd_bat_simple="bat --plain --wrap=never --tabs=0 --color=always --paging=never '$SRC'" cmd_pygmentize="pygmentize -g '$SRC'" cmd_highlight="highlight -O truecolor '$SRC'" cmd_ccat="ccat --color=always '$SRC'" cmd_source_highlight="source-highlight --failsafe --infer-lang -f esc -i '$SRC'" cmd_hicat="hicat '$SRC'" cmd_coderay="coderay '$SRC'" cmd_rouge="rougify '$SRC'" cmd_clp="clp '$SRC'" hyperfine --warmup 3 \ "$cmd_bat" \ "$cmd_bat_simple" \ "$cmd_pygmentize" \ "$cmd_highlight" \ "$cmd_ccat" \ "$cmd_source_highlight" \ "$cmd_hicat" \ "$cmd_coderay" \ "$cmd_rouge" \ "$cmd_clp" \ ``` -------------------------------- ### List Available Themes Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt List all available syntax highlighting themes for Bat. This command is useful for discovering themes. ```bash bat --list-themes ``` -------------------------------- ### Search Help Files Using Location List Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Similar to :helpgrep, :lhelpgrep searches help files but uses the location list instead of the quickfix list. It can open a new help window or update the location list of an existing one. ```vim :lhelpgrep {pattern}[@xx] ``` -------------------------------- ### Install Latest Bat Master Version Source: https://github.com/sharkdp/bat/blob/master/doc/release-checklist.md Installs the latest development version of Bat from the master branch. This is used to test new features and ensure the command-line interface is up-to-date before a release. ```bash cargo clean && cargo install --locked -f --path . ``` -------------------------------- ### Escaped Characters Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/HTML/test.html Shows how various special characters are handled and displayed. ```HTML Here are some escaped characters: & (ampersand), à (a with grave), № (numero sign). ``` -------------------------------- ### Literal Block Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/AsciiDoc/test.adoc Shows a literal block where line breaks are preserved. ```text This is a literal block where linebreaks are rendered ``` -------------------------------- ### TOML Syntax Mapping with Environment Variables Source: https://github.com/sharkdp/bat/blob/master/src/syntax_mapping/builtins/README.md Illustrates using environment variables like XDG_CONFIG_HOME and HOME within glob patterns for dynamic path handling in TOML syntax mappings. ```toml # 30-foo-application.toml [mappings] "TOML" = [ # rules for TOML syntax go here "/usr/share/foo-application/toml-config/*.conf", "/etc/foo-application/toml-config/*.conf", "${XDG_CONFIG_HOME}/foo-application/toml-config/*.conf", "${HOME}/.config/foo-application/toml-config/*.conf", ] "YAML" = [ # rules for YAML syntax go here # ... ] ``` -------------------------------- ### Get 'bat' cache directory Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Retrieves the cache directory used by the 'bat' command. ```shell _ [1;33m [Kbat [m [K_:run() { cache_dir="$($ [1;33m [KBAT [m [K --cache-dir)" } ``` -------------------------------- ### reStructuredText Simple Table Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/reStructuredText/reference.rst A simple table example in reStructuredText, demonstrating input/output columns for logical operations. ```rst ===== ===== ====== Inputs Output ------------ ------ A B A or B ===== ===== ====== False False False True False True False True True True True True ===== ===== ====== ``` -------------------------------- ### Create Syntax Definitions Folder Source: https://github.com/sharkdp/bat/blob/master/README.md Creates a directory for new syntax definitions within bat's configuration directory and clones a PureScript syntax definition into it. ```bash 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 ``` -------------------------------- ### Specifying Configuration File Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Shows how to specify a custom configuration file for bat using the --config-file option. This allows for advanced customization beyond environment variables. ```bash bat --config-file /path/to/custom/bat.conf ``` -------------------------------- ### Check Bat Version Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Verify that the Bat executable is installed and available in the system's PATH by checking its version. ```bash bat --version ``` -------------------------------- ### C# Case Statement with Enum Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Example of a C# case statement within a switch, referencing an enum value. ```csharp case BLBodyBatleLibrary.ContextType.TapUp: ``` -------------------------------- ### SSH Config YAML Option Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt An example of a configuration option within an SSH config file written in YAML. ```yaml assets/syntaxes/02_Extra/ssh-config/src/options.yaml ``` -------------------------------- ### Build Binary Cache for Syntaxes Source: https://github.com/sharkdp/bat/blob/master/README.md Parses new syntax definition files and builds a binary cache for bat to use. ```bash bat cache --build ``` -------------------------------- ### Search Help for Control Key Combination Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Shows how to search for help on control key combinations by using caret notation. ```vim :help ^V ``` -------------------------------- ### Filter environment variables for 'BAT' or 'PAGER' Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Filters environment variables to show lines starting with 'BAT_' or 'PAGER'. ```shell _ [1;33m [Kbat [m [K_:run() { _out env | grep '^ [1;33m [KBAT [m [K_|^PAGER=' } ``` -------------------------------- ### Compile Bat with Custom Syntax and Themes Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Instructions for compiling the Bat executable with custom syntax highlighting and themes. ```bash # Компилирование исполняего файла bat с другим синтаксисом и темами ``` -------------------------------- ### Build bat from FreeBSD ports Source: https://github.com/sharkdp/bat/blob/master/README.md Navigate to the FreeBSD ports directory for bat and build it. ```bash cd /usr/ports/textproc/bat make install ``` -------------------------------- ### Rust Main Function with Rectangle Source: https://github.com/sharkdp/bat/blob/master/tests/snapshots/output/changes_grid.snapshot.txt Instantiates a Rectangle and prints its perimeter. Includes an example of printing raw string literals. ```rust fn main() { let rect1 = Rectangle { width: 30, height: 50 }; println!( "The perimeter of the rectangle is {} pixels.", perimeter(&rect1) ); println!(r#"This line contains invalid utf8: ``` -------------------------------- ### Verifying Custom Syntax Recognition Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This command checks if the custom syntax 'BatTestCustomAssets' is correctly recognized by 'bat' after installation and asset building. ```shell bat -f "${custom_syntax_args[@]}" || ``` -------------------------------- ### Shell Command: Build Bat with Custom Syntaxes/Themes Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This command is a placeholder comment indicating how to build a bat binary with modified syntaxes and themes. Actual build commands would follow. ```shell # Build a bat binary with modified syntaxes and themes ``` -------------------------------- ### List 'bat' themes Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Prints the list of themes supported by 'bat' to standard output. ```shell _ [1;33m [Kbat [m [K_:run() { _print_command "$ [1;33m [KBAT [m [K" "--list-themes" } ``` -------------------------------- ### Quoted Text Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/AsciiDoc/test.adoc Shows how to format quoted text, potentially attributed to a source. This is distinct from a blockquote and can be used for shorter quotes. ```asciidoc [quote, Albert Einstein, 'Scientist'] ____ This is not actually something Einstein said ____ ``` -------------------------------- ### TypeScript Affected Files Retrieval Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This snippet indicates the process of getting the next batch of affected files during a compilation or analysis process. ```typescript // Get next ver\tbat\timch of affected files ``` -------------------------------- ### External Library Integration Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/CMake/CMakeLists.txt Finds the 'assimp' package and links it to the 'hello-bat' target. ```cmake find_package(assimp CONFIG) target_link_libraries(hello-bat assimp) ``` -------------------------------- ### Build Debug Version Source: https://github.com/sharkdp/bat/blob/master/README.md Compile the bat project in debug mode. This command is typically run after cloning the repository and before running tests or installing. ```bash cd bat cargo build --bins ``` -------------------------------- ### Search All Help Files for a Pattern Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt The :helpgrep command searches all help text files for lines matching a given pattern. It uses Vim regular expressions and can optionally specify a language for the search. Matches are navigated using quickfix commands. ```vim :helpgrep Uganda ``` ```vim :helpgrep uganda\c ``` ```vim :helpgrep backspace@fr ``` -------------------------------- ### Search Help for Control Key in Insert Mode Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Demonstrates searching for help on a control key combination specifically within Insert mode. ```vim :help i^V ``` -------------------------------- ### reStructuredText Grid Table Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/reStructuredText/reference.rst A complex grid table example in reStructuredText, showcasing headers, body rows, and cells that can span columns or rows. ```rst +------------+------------+-----------+ | Header 1 | Header 2 | Header 3 | +============+============+===========+ | body row 1 | column 2 | column 3 | +------------+------------+-----------+ | body row 2 | Cells may span columns.| +------------+------------+-----------+ | body row 3 | Cells may | - Cells | +------------+ span rows. | - contain | | body row 4 | | - blocks. | +------------+------------+-----------+ ``` -------------------------------- ### Rust Main Function with Rectangle Perimeter Source: https://github.com/sharkdp/bat/blob/master/tests/snapshots/output/changes.snapshot.txt Demonstrates creating a Rectangle instance and printing its perimeter. Includes an example of printing invalid UTF-8. ```rust fn main() { let rect1 = Rectangle { width: 30, height: 50 }; println!( "The perimeter of the rectangle is {} pixels.", perimeter(&rect1) ); println!(r#"This line contains invalid utf8: "�����"#; } ``` -------------------------------- ### Add New Syntax Test Files Source: https://github.com/sharkdp/bat/blob/master/doc/assets.md Stage the new source file and the autogenerated highlighted file for the new syntax test. ```bash git add tests/syntax-tests/source/Ruby/test.rb tests/syntax-tests/highlighted/Ruby/test.rb ``` -------------------------------- ### Create Themes Folder and Clone Theme Source: https://github.com/sharkdp/bat/blob/master/README.md Creates a directory for custom themes and clones a Sublime Text theme in .tmTheme format. ```bash 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 ``` -------------------------------- ### Defining a Section Separator Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/VimHelp/helphelp.txt Use a series of '=' characters starting from the first column to visually separate sections in a help file. ```Vim Help ================================================================================ ``` -------------------------------- ### Mapping Extension to Unknown Source: https://github.com/sharkdp/bat/blob/master/src/syntax_mapping/builtins/README.md Demonstrates how to explicitly map file extensions to an unknown syntax type, preventing specific syntaxes from claiming files they shouldn't. ```toml # 99-unset-ambiguous-extensions.toml [mappings] "MappingTarget::MapExtensionToUnknown" = [ "*.conf", ] ``` -------------------------------- ### Configure Pager for Bat Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This example shows how to set the BAT_PAGER environment variable to use 'less -RF' as the pager, overriding the default or PAGER variable. ```shell export BAT_PAGER="less -RF" ``` -------------------------------- ### Source File Discovery Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/CMake/CMakeLists.txt Sets a source directory and recursively finds all .c files within it. ```cmake set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/") file(GLOB_RECURSE SOURCES "${SOURCE_DIR}/*.c") ``` -------------------------------- ### Create Themes Folder for Bat Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Create the necessary directory structure for custom Bat themes. ```bash mkdir -p "$(bat --config-dir)/themes" ``` -------------------------------- ### Running Bat Benchmark with Python File and Plain Style Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Runs a benchmark for 'bat' on a Python file, specifying plain text output and no configuration. ```shell "$(printf "%q" "$BAT") --no-config --language=txt --style=plain test-src/test_multiarray.py" \ --command-name 'bat … --language=txt test_multiarray.py' \ ``` -------------------------------- ### Vim Help Link Syntax Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Shows the syntax for internal links within Vim help files, including link begin, content, and end punctuation. ```vim # ^ punctuation.definition.link.begin # ^^ markup.underline.link # ^ punctuation.definition.link.end ``` -------------------------------- ### Rust Struct Definition and Usage Source: https://github.com/sharkdp/bat/blob/master/tests/snapshots/output/grid_header.snapshot.txt Defines a 'Rectangle' struct and demonstrates its usage in the 'main' function. Includes examples of formatted printing and raw string literals. ```Rust struct Rectangle { width: u32, height: u32, } fn main() { let rect1 = Rectangle { width: 30, height: 50 }; println!( "The perimeter of the rectangle is {} pixels.", perimeter(&rect1) ); println!(r#"This line contains invalid utf8: "�����"#; } fn area(rectangle: &Rectangle) -> u32 { rectangle.width * rectangle.height } fn perimeter(rectangle: &Rectangle) -> u32 { (rectangle.width + rectangle.height) * 2 } ``` -------------------------------- ### Create a new file quickly Source: https://github.com/sharkdp/bat/blob/master/README.md Use bat to quickly create a new file by redirecting its output. This acts as a simple text editor. ```bash bat > note.md ``` -------------------------------- ### Basic Bat Usage Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Demonstrates the fundamental usage of the bat command to print syntax-highlighted file content. Bat supports a wide range of programming and markup languages. ```bash bat tests/syntax-tests/source/Manpage/bat-0.16.man ``` -------------------------------- ### Overriding Bat Styles Completely Source: https://github.com/sharkdp/bat/blob/master/README.md To completely override configured styles, use the --style argument to specify only the desired components. This example shows only line numbers. ```bash bat --style=numbers ``` -------------------------------- ### TypeScript Enum, Interface, and Class Example Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/Markdown/typescript.md Defines and uses a TaskManager class with enums and interfaces. This snippet showcases basic object-oriented programming and type safety in TypeScript. ```typescript enum Status { Pending, InProgress, Completed, } interface Task { id: number; title: string; status: Status; assignee?: string; } class TaskManager { private tasks: T[] = []; addTask(task: T): void { this.tasks.push(task); } getTasksByStatus(status: Status): T[] { return this.tasks.filter(task => task.status === status); } async fetchTasks(): Promise { // Simulate async fetch return new Promise(resolve => setTimeout(() => resolve(this.tasks), 500)); } } // Type guard function isTask(obj: any): obj is Task { return typeof obj.id === 'number' && typeof obj.title === 'string'; } // Usage const manager = new TaskManager(); manager.addTask({ id: 1, title: "Write docs", status: Status.Pending }); manager.addTask({ id: 2, title: "Review PR", status: Status.InProgress, assignee: "Alice" }); (async () => { const allTasks = await manager.fetchTasks(); allTasks.forEach(task => { if (isTask(task)) { console.log(`Task #${task.id}: ${task.title} [${Status[task.status]}]`); } }); })(); // Type assertion const unknownValue: unknown = { id: 3, title: "Test", status: Status.Completed }; const assertedTask = unknownValue as Task; console.log(assertedTask.title); ``` -------------------------------- ### Define a Help Tag Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/VimHelp/helphelp.txt Help tags are defined by enclosing the tag name in asterisks (*tag-name*). The tag name should be unique and ideally start with the plugin's name. ```vimscript *tag-name* ``` -------------------------------- ### Configure man pager with bat Source: https://github.com/sharkdp/bat/blob/master/README.md Set the `MANPAGER` environment variable to use `bat` as a colorizing pager for man pages. This example shows how to set it and then view a man page. ```bash export MANPAGER="bat -plman" man 2 select ``` -------------------------------- ### Navigate to Bat Themes Directory Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Change the current directory to the newly created themes folder for Bat. ```bash cd "$(bat --config-dir)/themes" ``` -------------------------------- ### TypeScript Type Assertion Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/Markdown/typescript.md This example shows how to use type assertion in TypeScript. It assigns an object to a variable with an 'unknown' type and then asserts it to a specific 'Task' type for accessing its properties. ```typescript // Type assertion const unknownValue: unknown = { id: 3, title: "Test", status: Status.Completed }; const assertedTask = unknownValue as Task; console.log(assertedTask.title); ``` -------------------------------- ### Override Tab Expansion for Pager Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This command demonstrates how to override bat's default tab expansion and let the pager handle tabs, useful for specific terminal setups. ```shell bat --tabs=0 ``` -------------------------------- ### Generate Help Tags for a Directory Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt The :helptags command generates the help tags file for a specified directory. Use 'ALL' to process all 'doc' directories within the 'runtimepath'. ```vim :helptags [++t] {dir} ``` ```vim :helptags ALL ``` -------------------------------- ### Navigate to Bat Directory Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Change the current directory to the cloned Bat project directory. ```bash cd bat ``` -------------------------------- ### Create a bash alias for batcat to bat Source: https://github.com/sharkdp/bat/blob/master/README.md This bash alias maps the command `bat` to `batcat`. Use this if `bat` is installed as `batcat` on your system and you prefer to use the `bat` command name. ```bash alias bat="batcat" ``` -------------------------------- ### Create a symlink for batcat to bat Source: https://github.com/sharkdp/bat/blob/master/README.md On older Debian/Ubuntu releases, `bat` might be installed as `batcat`. This creates a symbolic link in `~/.local/bin` to alias `batcat` to `bat`, ensuring consistent usage. ```bash mkdir -p ~/.local/bin ln -s /usr/bin/batcat ~/.local/bin/bat ``` -------------------------------- ### Output files and stdin in sequence Source: https://github.com/sharkdp/bat/blob/master/README.md Specify multiple files and stdin to be outputted in the given order. ```bash bat f - g ``` -------------------------------- ### Bash Script for Getting Bat Version Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This snippet defines a Bash function to retrieve the version of the 'bat' command. It uses 'bat --version' and 'cut' to extract the version number. ```bash bat_version(){ "bat" --version|cut -d ' ' -f 2 ``` -------------------------------- ### View Help Matches with Completion Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Triggers command-line completion to show possible matches for a help subject. Useful for exploring available help tags. ```vim :help cont ``` -------------------------------- ### :help! command for non-English files Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/highlighted/VimHelp/helphelp.txt The :help! command is similar to :help but prioritizes finding a tag in a file matching the current file's language, useful for non-English help files. ```vim :help! [subject] ``` -------------------------------- ### Get bat version using command substitution Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This snippet captures the output of the 'bat --version' command and processes it using 'cut' to extract the version number. This is useful for version-specific logic. ```Bash "bat --version" | cut -d ' ' -f 2 ``` -------------------------------- ### Generate Help Tags Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Use the :helptags command to generate or update the tags file for help documentation in a specified directory. This command overwrites existing tags files silently. ```vim :helptags $VIMRUNTIME/doc ``` -------------------------------- ### Quoting Ex-Commands in Vim Help Source: https://github.com/sharkdp/bat/blob/master/assets/syntaxes/02_Extra/syntax_test_helphelp.txt Use a '>' at the end of the preceding line and a '<' at the beginning of a new line to quote a block of ex-commands verbatim. Any line starting in column 1 also stops the block. ```vimhelp > function Example_Func() echo "Example" endfunction < ``` -------------------------------- ### Adding Custom Sublime Themes Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt Details the process of installing custom Sublime Text .tmTheme themes for bat. Similar to custom languages, themes are placed in the config directory and require a cache rebuild. ```bash mkdir -p "$(bat --config-dir)/themes" ``` ```bash bat cache --build ``` -------------------------------- ### Jump to Specific Help Subject Source: https://github.com/sharkdp/bat/blob/master/tests/syntax-tests/source/VimHelp/helphelp.txt Opens the help window and jumps to the tag specified by {subject}. Supports wildcards in the subject. If multiple matches exist, a sophisticated algorithm selects the best one. ```vim :h[elp] {subject} ``` -------------------------------- ### Conditional logic based on bat version Source: https://github.com/sharkdp/bat/blob/master/tests/benchmarks/highlighting-speed-src/grep-output-ansi-sequences.txt This snippet checks if the installed bat version is greater than '0.12'. This allows scripts to conditionally execute features or use different commands based on the bat version. ```Bash if version_compare "$(bat_version)" -gt "0.12"; then ```