hachyderm.io is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hachyderm is a safe space, LGBTQIA+ and BLM, primarily comprised of tech industry professionals world wide. Note that many non-user account types have restrictions - please see our About page.

Administered by:

Server stats:

9.3K
active users

Bozhidar Batsov (a.k.a. Bug)

When showing shell commands in a file, which language are using for the fenced block?

```shell
$ foo --bar --baz
```

Everyone seems to be doing something different and I'm curious what's the "right" way. I'm also wondering why markdownlint hates such blocks (with a $), if they don't produce any output. That seems a bit arbitrary to me.

@bbatsov I have two hot takes here:

  • "shell" isn't a language. If it's a bash script, use "bash" so I know not to paste it into my fish shell.

  • Lose the dollar sign. This is a code block, and the dollar sign isn't part of the code. Especially relevant for code I'm likely to be pasting into my terminal. Also likely to confuse learners who are unaware of what it's supposed to represent.

@bodil Fair points, but there's also the counter-argument that the $ makes it obvious that something is a command one needs to enter in some shell. (if they are familiar with shells) I'm guessing that why so many people put them in their snippets.

@bbatsov I think so many people put them in their snippets just because they see others doing it, tbh.

@bodil @bbatsov I follow Bodil's way for standalone commands, and as `console` with prompt for examples that include both input and output. I also don't love the latter. I haven't found markup that visually keeps input with output together, while keeping input trivially copiable.

@bodil @bbatsov I always assumed "shell" meant a POSIX compatible shell.

I avoid $ unless I'm showing both commands and output in one section, but then I also wouldn't use shell syntax highlighting in that case.

@weavejester @bodil I’m pretty sure that “console” is the way to go when there’s actual output.

@bodil @bbatsov some people set their shell prompt to ';' to make copy and pasting easier (don't have to worry about the prompt). I haven't taken the plunge, but it seems like a good way to live.

@hiredman @bodil First time I hear of this, but I guess it certainly solves that particular problem. :D

@bbatsov I agree with markdownlint here. And that language should be set to ${SHELL##*/}.