From 4ba45e2ba24b84dceeed0da05b371c00638bd931 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Sat, 31 Aug 2019 14:32:37 +0200 Subject: [PATCH] Add first version of 'man page' syntax, closes #523 --- README.md | 11 +++++++ assets/syntaxes/Manpage.sublime-syntax | 44 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 assets/syntaxes/Manpage.sublime-syntax diff --git a/README.md b/README.md index fb200ae3..0bda2b55 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,17 @@ bat main.cpp | xclip ``` `bat` will detect that the output is being redirected and print the plain file contents. +#### `man` + +`bat` can be used as a pager for `man`. It can be used like this: +``` +export MANPAGER="sh -c 'col -b | bat -l man -p'" + +man 2 select +``` + +The [Manpage syntax](assets/syntaxes/Manpage.sublime-syntax) is developed in this repository and still needs some work. + ## Installation ### On Ubuntu diff --git a/assets/syntaxes/Manpage.sublime-syntax b/assets/syntaxes/Manpage.sublime-syntax new file mode 100644 index 00000000..227bccfe --- /dev/null +++ b/assets/syntaxes/Manpage.sublime-syntax @@ -0,0 +1,44 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: Manpage +file_extensions: + - man +scope: source.man + +variables: + section_heading: '^\S.*$' + +contexts: + main: + - match: ^ + push: first_line + + first_line: + - match: '([A-Z0-9]+)(\()([^)]+)(\))' + captures: + 1: meta.preprocessor + 2: keyword.operator + 3: string.quoted.other + 4: keyword.operator + + - match: '$' + push: body + + body: + - match: '^(SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)' + push: Packages/C/C.sublime-syntax + scope: markup.heading + with_prototype: + - match: '(?={{section_heading}})' + pop: true + + - match: '^\S.*$' + scope: markup.heading + + - match: '\b([a-z0-9_]+)(\()([^)]*)(\))' + captures: + 1: entity.name.function + 2: keyword.operator + 3: constant.numeric + 4: keyword.operator