ochre CLI

Command-line interface for the ochre syntax highlighter.

Synopsis

ochre LANG [FILE] [OPTION]...

Arguments

Options

Examples

Highlight an OCaml file to HTML

Using the bundled OCaml grammar and the default theme:

ochre ocaml file.ml

Highlight from stdin with ANSI terminal colors:

cat file.js | ochre javascript --format ansi

Dual-theme HTML output

ochre ocaml file.ml --theme-light light --theme-dark tokyonight

Load multiple grammars (e.g. for embedded languages)

Bundled grammars can be added by name with --include:

ochre html index.html --include css --include javascript

Custom grammar files are loaded with --grammar:

ochre html index.html \
  --grammar ./grammars/html.tmLanguage.json \
  --grammar ./grammars/css.tmLanguage.json \
  --grammar ./grammars/javascript.tmLanguage.json \
  --theme theme.json

or using the short flags:

ochre html index.html -g ./grammars/html.tmLanguage.json -i css -i javascript

Grammars

ochre bundles the grammars from the tm-grammars package, covering 200+ languages. When no --grammar flag is given, the bundled grammar matching LANG is used; if there is none, the CLI lists the available names.

The language identifiers plaintext, text, and txt need no grammar: they render the input as unstyled tokens with the theme's default colors.

To use a custom grammar, pass --grammar with a path to a .tmLanguage.json file. The language identifier is derived from the filename (e.g. ocaml.tmLanguage.json registers as ocaml). Common sources for grammar files:

Themes

Themes use the VS Code / TextMate JSON format with colors and tokenColors fields. See VS Code Theme Gallery for available themes.

For the CLI, --theme is optional. ochre uses a built-in theme and auto-picks dark/light from your terminal (using OCHRE_THEME_MODE, TERM_THEME, or COLORFGBG).

You can also pass a built-in name directly, for example --theme dark, instead of a file path.

Built-in themes: