Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style-guide: document use of POSIX-compliant shell syntax in subdirectory common #12894

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

tricantivu
Copy link
Member

@tricantivu tricantivu commented Jun 4, 2024

  • [N/A] The page(s) are in the correct platform directories: common, linux, osx, windows, sunos, android, etc.
  • [N/A] The page(s) have at most 8 examples.
  • [N/A] The page description(s) have links to documentation or a homepage.
  • The page(s) follow the content guidelines.
  • The PR title conforms to the recommended templates.
  • Version of the command being documented (if known): N/A

Closes #12694.

I decided to suggest rather than oblige (hence the should be written...) users to write command examples with POSIX-compliant shell syntax because I and probably other reviewers will agree that some pages could become less useful in the long run.

@github-actions github-actions bot added the documentation Issues/PRs modifying the documentation. label Jun 4, 2024
@tricantivu tricantivu changed the title style-guide: document use of POSIX-compliant shell syntax style-guide: document use of POSIX-compliant shell syntax in subdirectory common Jun 5, 2024
contributing-guides/style-guide.md Show resolved Hide resolved
contributing-guides/style-guide.md Outdated Show resolved Hide resolved
> More information: <https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html>.
```

To help you decide using POSIX-compliant syntax, ask yourself this:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the wording of this section, maybe we can reword it a bit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To help you decide using POSIX-compliant syntax, ask yourself this:
To help you decide using POSIX-compliant syntax, use the below questions:

contributing-guides/style-guide.md Outdated Show resolved Hide resolved
Co-authored-by: K.B.Dharun Krishna <[email protected]>
@gutjuri
Copy link
Member

gutjuri commented Jun 5, 2024

I personally see no reason why tldr should be POSIX compliant... In my view, this project's aim is to be useful for beginners, showing them how to do useful, real-world stuff. Restricting yourself to the POSIX standard is not real-world at all, basically everyone uses modern shells like bash or zsh that allow for convenience features like process substitution.

I argue that users that restrict themselves to pure POSIX shells, be it for ideological reasons or limitations of their system (e.g. if they work with embedded devices), are very well aware of the limitations of this choice and will not be surprised if some examples in tldr cannot be copy-pasted on their system.

I would be in favour to remain non-compliant to POSIX, at least a little bit where it makes sense. E.g., lets keep process substitution but remove instances of <<< if some modern shells do not support this.

@spageektti
Copy link
Member

@gutjuri I think beginners don't even care if they use bash or something else. They just use terminal, probably the default for their system. I don't care either (I'm just using bash which is the default on Fedora).
We can make our examples POSIX compliant if that makes sense (it doesn't mess up or complicate anything).

Comment on lines +405 to +409
To help you decide using POSIX-compliant syntax, ask yourself this:

- Is the example too long (i.e. [exceeds the maximum line length](https://github.com/tldr-pages/tldr/blob/main/.markdownlint.json#L5))?
- Does the example utilize any [risky](https://unix.stackexchange.com/a/278439) or [inefficient](https://unix.stackexchange.com/a/169765) commands?
- Does the example return the correct output?
Copy link
Member

@vitorhcl vitorhcl Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To help you decide using POSIX-compliant syntax, ask yourself this:
- Is the example too long (i.e. [exceeds the maximum line length](https://github.com/tldr-pages/tldr/blob/main/.markdownlint.json#L5))?
- Does the example utilize any [risky](https://unix.stackexchange.com/a/278439) or [inefficient](https://unix.stackexchange.com/a/169765) commands?
- Does the example return the correct output?
As more of the points below apply, so does the recommendation to not use POSIX-compliant syntax in a particular example:
- The example is not implemented in at least one version
- The example is too long (i.e. [exceeds the maximum line length](https://github.com/tldr-pages/tldr/blob/main/.markdownlint.json#L5))
- The example utilize any [risky](https://unix.stackexchange.com/a/278439) or [inefficient](https://unix.stackexchange.com/a/169765) commands?
- The example doesn't return the correct output in some or all implementations

How about this? @kbdharun @sebastiaanspeck @tricantivu

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO questions makes things a bit too open and a bit confusing (a positive answer means that I should use POSIX-compliant syntax or not?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO questions makes things a bit too open and a bit confusing (a positive answer means that I should use POSIX-compliant syntax or not?)

Perhaps I could replace the questions for a guide explaining how to check POSIX-compliance (e.g. shellcheck -s sh -).

@vitorhcl
Copy link
Member

vitorhcl commented Jun 6, 2024

In my opinion, tldr should mostly be POSIX compliant if the platform is common, but not necessarily in linux, macos, sunos or BSDs. Targeting POSIX makes tldr more likely to be useful for all kinds of users and for any POSIX-compliant (or partially compliant) OS, given that OS-specific versions are preferred when getting a page (or should, according to the tldr client specification).

In my view, this project's aim is to be useful for beginners, showing them how to do useful, real-world stuff.

IMO the project is targeted at all types of users. Obviously it is useful for begginers, but I definitely see how it can be useful for mid-level users and even for extremely experienced users.

For example, one can have a deep knowledge in a specific area but doesn't know how to use a new tool. If the person wants to just get the most useful examples quickly, tldr can be used, instead of reading the official documentation (if any) or manual pages.

Restricting yourself to the POSIX standard is not real-world at all

If we target all popular Unix-like platforms, from Linux to BSDs, we should try to use POSIX. Particularly, OpenBSD tries to follow POSIX for most of their commands.

POSIX is basically the only way to assure cross-compability with even some more obscure OSes, which adds, in the long term, a big value to tldr at a relatively low cost.

basically everyone uses modern shells like bash or zsh that allow for convenience features like process substitution.

BSDs don't use neither bash or zsh, common should try to be the more cross-compatible as possible.

Also, POSIX compliance is important in the shell scripting community.

I would be in favour to remain non-compliant to POSIX, at least a little bit where it makes sense. E.g., lets keep process substitution but remove instances of <<< if some modern shells do not support this.

Your example is a good one. If that syntax is not supported in "modern shells" (bash, zsh and fish?), IMO we should keep them in linux, where they are more popular (maybe add a note that it is not POSIX-compliant and thus doesn't work at, for example, sh or dash, simpler shells in general).

I see no problem if, for example, if the linux or macos versions provides OS-specific commands while the common provides POSIX commands, since this doesn't affect users because of the tldr client specification.


Edit.: In my view, we should:

  • In linux pages, prefer bash commands if not POSIX
  • In macos pages, prefer zsh commands if not POSIX
  • In other platforms (sunos and BSDs), prefer POSIX or the default shell of the platform
  • In common, prefer POSIX as much as possible, and if necessary, deviating from it by using commands only present in platforms in which the command is most useful, most popular or something like that. Example:
    • Even though nix is available for all platforms, it is more popular in NixOS, so it makes sense to use NixOS-specific commands
    • There can be a tool that is available for all major platforms but is more popular in FreeBSD, for example, so it makes sense to use FreeBSD-specific options

If a not universal command or option is used, a note or warning should be used.

tricantivu and others added 2 commits June 6, 2024 20:32
Co-authored-by: K.B.Dharun Krishna <[email protected]>
@tricantivu
Copy link
Member Author

We can make our examples POSIX compliant if that makes sense (it doesn't mess up or complicate anything).

Only for pages in common.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do lines 398-411 have an extra space at the start of each line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues/PRs modifying the documentation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: document shell syntax (i.e. here-strings, etc) for commands in the common directory
6 participants