aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/_posts/2022-03-21-shell.md
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--_posts/2022-03-21-shell.md52
1 files changed, 52 insertions, 0 deletions
diff --git a/_posts/2022-03-21-shell.md b/_posts/2022-03-21-shell.md
new file mode 100644
index 0000000..1f8f56a
--- /dev/null
+++ b/_posts/2022-03-21-shell.md
@@ -0,0 +1,52 @@
+---
+title: Shell commands
+excerpt: >
+ Pretty formatting for shell commands and their outputs.
+---
+It's easy to style shell commands and their outputs.
+Here's a one-line command and a one-line output.
+
+{% include shell.html cmd='echo 1' out='1' %}
+
+You can pass multiple commands and multi-line output to the include as well:
+
+{% include 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 shell.html cmd=cmd1 out=out1 %}
+
+You can display multiple commands one after another.
+
+{% include shell.html cmd="printf 'Hello\n'" out='Hello' %}
+{% include 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 shell.html cmd=cmd1 out=out1 %}
+
+This is ugly though, so please don't do that.