Hacker News new | ask | show | jobs
by ehamberg 4513 days ago
If you want a solid line, you could use U+2501 (━) from the set of box drawing characters (https://en.wikipedia.org/wiki/Box-drawing_character):

    <━> 9473, U+2501 BOX DRAWINGS HEAVY HORIZONTAL

    hr(){printf '━%.0s' $(seq $COLUMNS)}
4 comments

Indeed, printf is shorter. I use it in a similar fashion in my own script [1], which can be made to behave like hr() (haven't tried shells other than bash):

    centered_output '=' ''
[1] https://github.com/ppurka/sh_functions/blob/master/my_bash_f...
Some terminals support ACS (with SCLD) but not unicode. It might be better to use ACS:

    $ hr() { printf '\e(0'; printf 'q%.0s' $(seq $(tput cols)); printf '\e(B'; }
Same thing, but potentially more portable.

edit: Could also use tput instead of $COLUMNS. Sometimes the $COLUMNS may not always be updated (bash's checkwinsize option).

For portability you should also use \033 (the octal code) instead of \e, which is non-standard.
And now it works in the bourne shell!
If you want to conform to ANSI, just use two dashes (--) or ASCII, the box drawing character, the source of the unicode variant. This is important because it remains the primary font in the core of any EGA and VGA-compatible graphics card (basically all graphics cards).
ASCII doesn't have box drawing characters. ASCII is codepoints 0-127.
I'm talking about the IBM set that is most common in western locals, often called extended ASCII or just ASCII (since IBM PC became the standard)