aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/_posts/2022-03-21-shell.md
blob: d48be628da29bddc28a2c9291b2de495cbfc1f70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: Shell commands
excerpt: >
  Pretty formatting for shell commands and their outputs.
category: Work
---
It's easy to style shell commands and their outputs.
Here's a one-line command and a one-line output.

{% include jekyll-theme/shell.html cmd='echo 1' out='1' %}

You can pass multiple commands and multi-line output to the include as well:

{% include jekyll-theme/shell.html cmd='echo 1
echo 2' out='1
2' %}

However, it is recommended that you `capture` multi-line commands and outputs
into variables and pass them.
This is mostly because Liquid doesn't like backslashes too much.

{% capture cmd1 %}
touch test.txt && \
    echo 123 >> test.txt && \
    echo 456 >> test.txt && \
    cat test.txt
{% endcapture %}
{% capture out1 %}
123
456
{% endcapture %}

{% include jekyll-theme/shell.html cmd=cmd1 out=out1 %}

You can display multiple commands one after another.

{% include jekyll-theme/shell.html cmd="printf 'Hello\n'" out='Hello' %}
{% include jekyll-theme/shell.html cmd="printf 'World\n'" out='World' %}

Only the last one will have a bottom margin.

Also, here's a really long command with a really long output:

{% capture cmd1 %}
printf '%s\n' 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
{% endcapture %}
{% capture out1 %}
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
{% endcapture %}

{% include jekyll-theme/shell.html cmd=cmd1 out=out1 %}

This has the potential to look rather ugly due to scrollbars though, so please
don't do that.

Commands don't necessarily have to have output:

{% include jekyll-theme/shell.html cmd='mkdir test' %}
{% include jekyll-theme/shell.html cmd='cd test' %}