How to use

This is intended for code blocks (<pre><code>) and not for inline code.

Add class command-line to your <pre>. For a server command line, specify the user and host names using the data-user and data-host attributes. The resulting prompt displays a # for the root user and $ for all other users. For any other command line, such as a Windows prompt, you may specify the entire prompt using the data-prompt attribute.

Optional: Command output (positional)

You may specify the lines to be presented as output (no prompt and no highlighting) through the data-output attribute on the <pre> element in the following simple format:


The 5th line
Lines 1 through 5
Line 1 and line 4
1-2, 5, 9-20
Lines 1 through 2, line 5, lines 9 through 20

Optional: Command output (prefix)

To automatically present some lines as output, you can prefix those lines with any string and specify the prefix using the data-filter-output attribute on the <pre> element. For example, data-filter-output="(out)" will treat lines beginning with (out) as output and remove the prefix.

A blank line will render as an empty line with a prompt. If you want an empty line without a prompt then you can use a line containing just the output prefix, e.g. (out). See the blank lines in the examples below.

Output lines are user selectable by default, so if you select the whole content of the code block, it will select the shell commands and any output lines. This may not be desirable if you want to copy/paste just the commands and not the output. If you want to make the output not user selectable then add the following to your CSS:

.command-line span.token.output {
	user-select: none;

Optional: Multi-line commands

You can configure the plugin to handle multi-line commands. This can be done in two ways; setting a line continuation string (as in Bash); or explicitly marking continuation lines with a prefix for languages that do not have a continuation string/character, e.g. SQL, Scala, etc..

Set this attribute to the line continuation string/character, e.g. for bash data-continuation-str="\"
This works in a similar way to data-filter-output. Prefix all continuation lines with the value of data-filter-continuation and they will be displayed with the prompt set in data-continuation-prompt. For example, data-filter-continuation="(con)" will treat lines beginning with (con) as continuation lines and remove the prefix.
Set this attribute to define the prompt to be displayed when the command has continued beyond the first line (whether using line continuation or command termination), e.g. for MySQL data-continuation-prompt="->". If this attribute is not set then a default of > will be used.


Default Use Without Output

<pre class="command-line">
cd ~/.vim

vim vimrc

Root User Without Output

<pre class="command-line"
cd /usr/local/etc
cp php.ini php.ini.bak
vi php.ini

Non-Root User With Output

<pre class="command-line"
     data-output="2, 4-8">
ls -la
total 2
drwxr-xr-x   2 chris  chris     11 Jan 10 16:48 .
drwxr--r-x  45 chris  chris     92 Feb 14 11:10 ..
-rwxr-xr-x   1 chris  chris    444 Aug 25  2013 backup
-rwxr-xr-x   1 chris  chris    642 Jan 17 14:42 deploy

Windows PowerShell With Output

<pre class="command-line"
     data-prompt="PS C:\Users\Chris>"

    Directory: C:\Users\Chris

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d-r--        10/14/2015   5:06 PM            Contacts
d-r--        12/12/2015   1:47 PM            Desktop
d-r--         11/4/2015   7:59 PM            Documents
d-r--        10/14/2015   5:06 PM            Downloads
d-r--        10/14/2015   5:06 PM            Favorites
d-r--        10/14/2015   5:06 PM            Links
d-r--        10/14/2015   5:06 PM            Music
d-r--        10/14/2015   5:06 PM            Pictures
d-r--        10/14/2015   5:06 PM            Saved Games
d-r--        10/14/2015   5:06 PM            Searches
d-r--        10/14/2015   5:06 PM            Videos

Line continuation with Output (bash)

<pre class="command-line"
     data-continuation-str="\" >
export MY_VAR=123
echo "hello"
echo one \
two \
(out)one two three
echo "goodbye"

Line continuation with Output (PowerShell)

<pre class="command-line"
     data-prompt="ps c:\users\chris>"
     data-continuation-str=" `">
Write-Host `
'Hello' `
'from' `
(out)Hello from PowerShell!
Write-Host 'Goodbye from PowerShell!'
(out)Goodbye from PowerShell!

Line continuation using prefix (MySQL/SQL)

<pre class="command-line"
set @my_var = 'foo';
set @my_other_var = 'bar';
(con)first_name VARCHAR(30) NOT NULL,
(con)last_name VARCHAR(30) NOT NULL
(out)Query OK, 0 rows affected (0.09 sec)
insert into people
(con)values ('John', 'Doe');
(out)Query OK, 1 row affected (0.02 sec)
select *
(con)from people
(con)order by last_name;
(out)| first_name | last_name |
(out)| John       | Doe       |
(out)1 row in set (0.00 sec)