At times when living my life in the terminal I run many commands in quick succession that might produce a lot of output. Differencing where the output actually comes from can be tiresome. Previously I’ve done simple things like

command1 ; echo -- ; command2

but it’s not exactly visually striking, is it?

So I crafted a little tool that solves this problem in a better way, and it tries to be smart about it, too. By default, we try to determine the size of the terminal window to make sure the hr spans across nicely. The size of the bar can be configurable; maybe you don’t want the bar to span the entire terminal:

hr -s 10

or maybe you want it to span the entire window, but you’d like some padding:

hr --pre 10

wouldn’t it be nice to have padding on both sides, though?

hr --pre 10 --post 10

We can add a bit of color to it as well, to make it stand out more from the rest of the data on screen:

hr --pre 10 --post 10 -fg 196

and of course the actual character that’s used to create the bar is configurable:

hr --pre 10 --post 10 -fg 196 -c #

hr supports foreground and background colors, as well as all attributes available in Term::ExtendedColor (well, except blink…).

Here’s a screenshot of what it can look like in a chain of commands (more screenshots in the examples section, below):

Options

-c, --char Character to use -s, --size Number of columns -pre, --pre Pad the left side with whitespace n -post, --post Pad the right side with whitespace n -fg, --fg Foreground color to use, int 0-255 -bg, --bg Background color to use, int 0-255 -b, --bold Use bold -i, --italic Use italics -u, --underline Use underline -r, --reverse Use reverse video -h, --help Display this help and exit -m, --man Display the manual and exit -v, --version Display version info and exit

Examples

Due to the configurability of hr, differencing different hr invocations from each other is no problem.

# display a yellow underlined bar using the default '=' character hr -fg 220 --underline

# display a red solid bar padded by 10 columns from right and left hr -fg 160 -c ▀ --pre 10 --post 10

# display a solid grey, thick bar using ascii character _ and the bold, # underline and reverse video attributes hr -fg 240 -c_ -bur

# display a bar made of dots, with 5 column spacing one each size # and 20 columns wide. hr -fg 197 -c · -pre 5 -post 5 -size 20

# use all options at once, because why not? hr -c ! -fg 52 -bg 196 -biur -s 70 -pre 5 -post 5

Bonus: advanced example using arithmetics, because math is hard.

# use several characters to form a bar using arithmetics hr -c " japh " -fg 1 -bg 0 -b -s $(( $COLUMNS / 8 ))

hr is available on github as well as on the cpan, of course.