Print files with syntax highlighting
Two commands print files with colour: cmdop highlight, which is always a
highlighter, and cmdop cat, which is a drop-in replacement for cat.
cmdop highlight
cmdop highlight main.py
cmdop highlight -n config.yaml
cmdop highlight -l python script
cmdop highlight -t dracula main.go
cmdop highlight *.go| Flag | Purpose |
|---|---|
-n, --line-numbers | Show line numbers. |
-l, --language <lang> | Force a language instead of detecting it from the extension. |
-t, --theme <theme> | Colour theme. Default monokai. |
--list-languages | List supported languages. |
--list-themes | List available themes. |
cmdop cat
cmdop cat prints files like cat(1) and adds highlighting only when the
output is a terminal. It is a genuine drop-in in two ways:
- Piped or redirected output is the raw bytes — no colour, no decoration — so
cmdop cat main.go | grep funcbehaves exactly likecat. - Any real
cat(1)flag it cannot render itself (-b,-e,-n,-s,-t,-u,-v,-A, and the GNU long forms) is handed to the systemcatunchanged, so you get your platform’s authentic behavior and its authentic error messages.
cmdop cat main.go # highlighted in a terminal
cmdop cat a.py b.py # multiple files, each with a header
cmdop cat --number config.yaml # line numbers on the highlighted output
cmdop cat -n config.yaml # POSIX -n -> the system cat
cmdop cat --language json data
cmdop cat --color=always f | less -R # force colour through a pipeWith no file arguments, or with -, it reads standard input.
| Flag | Purpose |
|---|---|
--color auto|always|never | When to colorize. Default auto. |
-p, --plain | Never colorize. Same as --color=never. |
--number | Line numbers on the highlighted output. Note POSIX -n goes to the system cat instead. |
--language <lang> | Force a language. Note POSIX -l goes to the system cat. |
--theme <theme> | Colour theme. Default monokai. |
--install-alias | Print the shell alias cat='cmdop cat'; add --apply to append it to your shell rc file. |
To make it your cat:
cmdop cat --install-alias --applyLast updated on