package ochre-cli
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a8e38fbcd22fbb68b0f7d93b36a2ba1670e8bd061b43a0177226738307183a32
sha512=7b344c3812be283b0101078564e564732f878ad226c7ce0212c9e9139fb41a291e4d31ad52c949f2978c48e04240d4d22b5b4ae63808e15a21c44a2fbeed8a22
doc/cli.html
ochre CLI
Command-line interface for the ochre syntax highlighter.
Synopsis
ochre LANG [FILE] [OPTION]...
Arguments
LANG— Language identifier (e.g.ocaml,javascript,python). Required.FILE— Input file path. Optional when piping/redirection stdin is used.
Options
--theme NAME_OR_PATH,-t NAME_OR_PATH— Optional. Built-in theme name (for exampledark,light, ortokyonight) or path to a VS Code / TextMate theme JSON file.--theme-dark NAME_OR_PATH— Theme used when terminal mode is detected as dark (same name-or-path resolution as--theme). With--format html, when both--theme-darkand--theme-lightare given (and no--theme), produces dual-theme output: the light theme is the default and the dark theme is emitted as CSS custom properties (--ochre-dark-*) for automatic dark-mode switching.--theme-light NAME_OR_PATH— Theme used when terminal mode is detected as light (same name-or-path resolution as--theme). See--theme-darkfor dual-theme HTML output.--grammar FILE,-g FILE— Path to a.tmLanguage.jsongrammar file. Can be specified multiple times. Optional: when omitted, the bundled grammar forLANGis used.--include LANG_OR_PATH,-i LANG_OR_PATH— Additional grammar to load, by bundled name or file path. Use to enable cross-grammar features like HTML embedding CSS/JS. Can be specified multiple times.--format FORMAT,-f FORMAT— Output format:html(default),ansi,latex,svg, ortokens.--html-css-classes— Use CSS class names instead of inline styles for HTML output. Each unique style gets a deterministic class likeochre-<hash>.--line-numbers— Adddata-lineattributes to line spans in HTML output (1-indexed).--no-default-color— Suppress inline color/background-color on the primary theme; all colors come from CSS custom properties only. Useful with multi-theme output when you control theme switching entirely via CSS.--css-var-prefix PREFIX— CSS custom property prefix for multi-theme output (default:--ochre-).--scopes-data— Adddata-scopeattributes to token spans in HTML output with TextMate scope names.
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:
- VS Code extensions:
~/.vscode/extensions/ - shikijs/textmate-grammars-themes on GitHub
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:
dark— Default dark ochre themelight— Default light ochre themetokyonight— Based on the Tokyonight themeeverforest— Based on the Everforest themeayu— Based on the Ayu dark themecatppuccin— Based on the Catppuccin Mocha themecatppuccin-macchiato— Based on the Catppuccin Macchiato themegruvbox— Based on the Gruvbox dark medium themekanagawa— Based on the Kanagawa Wave themenord— Based on the Nord themematrix— Hacker-style green on black themeone-dark— Based on the Atom One Dark theme