A lot of the posts I write include command-line interface (CLI) commands to type in. I’ve found over time there are things I can do to improve how these commands are communicated.
HTML Markup
When writing a command inline, wrapping it in <code></code>
tags works well (e.g. ls
).
When you want to display it as a block, wrapping it in <pre><code></code></pre>
works well, e.g.
ls
The CLI Prompt
There are varying opinions on whether or not your examples should include your command prompt.
When to Include the Prompt?
My recommendation is to omit the command prompt in almost all cases. It is easier to copy the command when the prompt is not included (both manually and if you have a copy button associated with your block).
Style | Yes | No |
---|---|---|
Inline | ls |
$ ls |
Block |
|
|
Block w/ Output |
|
|
The only time I recommend including the prompt is when the block includes both the typed command and the output because in this case the prompt differentiates the command to be typed and the expected output.
Which Prompt?
In the rare occasions when you do include the prompt I recommend using $
(the default prompt in bash shell).
Leave a Reply