Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close

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

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.