On 2012-06-12, Federico Bruni wrote:
> Hi,

> the easiest way to enter shell commands is probably not using any $ and 
> # sign in front of the command and using sudo for commands to be run as 
> root.

> But it would be nice to handle it differently.

> I'd like to be able to define two styles for shell commands.
> I don't want to use "sudo" in the root commands.
> I'd like to enter only the real command in the literal block, with no 
> leading $ or # (because it's not handy for copy&paste).

> $ and # signs should be added by a style, that I may specify as a option 
> of the literal block.

> Something like this:

> Install the dependencies::
>     :user: root
>     aptitude install bla bla bla

> Run the program::
>     :user: user
>     python program.py


> What do you recommend to do?

a) use the "sh" lexer, give a class value to the input and use a custom
   style (CSS rule with class selector with HTML, tricky or maybe
   impossible with LaTeX/PDF)::
   
      .. code:: sh
         :class: user
         
         python program.py
         
      .. code:: sh
         :class: root
         
         python setup.py install
         
   (The "code" directive is new in reStructuredText (docutils 0.9
   (2012-05-02). Use the Sphinx extension "sourcecode" with earlier
   Docutils versions.)
      
b) Create and use Pygments lexers, e.g. "shell-user" vs. "shell-root" (or
   just use the existing "sh" lexer). See
   http://pygments.org/docs/lexers/#lexers-for-various-shells and
   http://pygments.org/docs/lexerdevelopment/

> Also, how can I style the shell commands differently from other literal 
> blocks?

Either use the "code" directive, ::

  .. code:: sh
  
     ls -l

or set the "default literal block style":

  The highlighting language can be changed using the highlight directive,
  used as follows::

    .. highlight:: c

  This language is used until the next highlight directive is
  encountered.

  -- http://sphinx.pocoo.org/markup/code.html

  
Günter

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to