From 0a28da0cd018f2602677dcb04f8abef9aaabf523 Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 11 Oct 2020 21:07:56 +0200 Subject: [PATCH] Small improvement to the syntax mapping section --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 24239ded..d42ea473 100644 --- a/README.md +++ b/README.md @@ -490,27 +490,32 @@ and the `GitHub` theme when in the _light mode_. alias cat="bat --theme=\$(defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo default || echo GitHub)" ``` -### Syntax of a file +### Adapting file type associations -You can change the default syntax association of the file using the `--map-syntax` option. -It supports glob pattern matching and is matched on full path and filename. +You can add new (or change existing) file name patterns using the +`--map-syntax` option. The option takes an argument of the form `pattern:syntax`. +`pattern` is a glob pattern that is matched against the file name and +the absolute file path. `syntax` is the *name* of a supported language +(use `bat --list-languages` for an overview). -You can use it like this: +This option is most useful in combination with the `bat` configuration file (see below). +Example: To use "INI" syntax highlighting for all files with a `.conf` file extension, use ```bash -bat --map-syntax='PATTERN:SYNTAX' file-name +--map-syntax='*.conf:INI' ``` -For example: +Example: To open all files called `.ignore` (exact match) with the "Git Ignore" syntax, use: ```bash -# Using `INI` file syntax highlighting when opening a file with extension `.conf`. -bat --map-syntax='*.conf:INI' file.conf - -# Using `Git Ignore` file syntax highlighting for ".ignore" files -bat --map-syntax='.ignore:Git Ignore' .ignore +--map-syntax='.ignore:Git Ignore' +``` + +Example: To open all `.conf` files in subfolders of `/etc/apache2` with the "Apache Conf" +syntax, use (this mapping is already built in): +```bash +-map-syntax='/etc/apache2/**/*.conf:Apache Conf' ``` -You can use `bat --list-languages` to see all the file syntax types available. ## Configuration file