Overview

Shell-Session Pygments Formatting

You have three possibilities to highlight shell sessions with pygments (in Sphinx or Tinkerer):

  • .. code-block:: bash
  • .. code-block:: console
  • .. code-block:: shell-session (new)

Have a look at the comparison.

Just run make to create the shell_code_comparison.html file, this will also generate a modified pygments.css, you will need Docutils >=0.9 and Pygments >=1.6.

You can also change the color of your command prompt inside pygments.css:

.highlight .go { color: #808080 } /* Generic.Output */
.highlight .gp { color: #18B218; font-weight: bold } /* Generic.Prompt */

Why:

The default .. sourcecode:: console directive will highlight every line that starts with #, $, > or user@linuxbox.

This lexer will highlight:

[user@host dir]$ ls test
user@host ~ $ ls test
user@host:~# ls test

and not lines starting with #, > or $.

How to use (in Sphinx or Tinkerer):

.. sourcecode:: shell-session

  [user@linuxbox ~]$ rpm -ql python-pygments |grep lexers/other
  /usr/lib/python2.7/site-packages/pygments/lexers/other.py
  /usr/lib/python2.7/site-packages/pygments/lexers/other.pyc
  /usr/lib/python2.7/site-packages/pygments/lexers/other.pyo
  [user@linuxbox ~]$

See it in action:

One of my blog posts that makes heavy use of the new shell-session lexer: http://www.jann.cc/2012/12/16/olinuxino_micro_usb_3g_modem_web_control.html