0

The aim is to to draw a line across a terminal using only zsh builtins.


Note that a similar question has been asked already about bash. This one is specific to zsh.

Pound Hash
  • 453
  • 1
  • 4
  • 13

1 Answers1

2

This code

print -- ${(l:COLUMNS::─:)}

Prints this line

──────────────────────────────────────────────────────────────

Note: The character (─) is a box drawing character, not a hyphen. Also, COLUMNS is a zsh parameter whose value is the width of the terminal. You could replace that with a specific width, e.g., 80.

Pound Hash
  • 453
  • 1
  • 4
  • 13
  • How does the form `${(....)}`, i.e. without a parameter name, work in general? An explanation would be helpful. BTW, I suggest in this case to use `${(l:COLUMNS::─:):-}` instead. This would then even work, if you have activated `set -u` in your shell. – user1934428 Nov 16 '22 at 08:34
  • 1
    Explanation is a pragmatic affair. I doubt more granularity would be so helpful here. If I explain the `l` flag, then why not explain the others? There comes a point when we should consult further reference materials in order to learn more. My feeling is that the concision here is warranted. – Pound Hash Nov 16 '22 at 19:36