Portable horizontal ruler for terminal
(SuperB HR) is a CLI tool written in
portable sh
to render horizontal ruler/line in the terminal.
Recently, i'm obsessed with hr
and i want a portable shell hr
, the best i found is "POSIX
-ish Way" from the blog Alternatives to the hr
library:
printf '%*s' "$(tput cols)" | tr ' ' "${*:-#}"
but it lacks Gil Gonçalves's hr
key features like output multiple line, custom text or even treats multi-byte symbols properly. So i decided to create based on the blog's method with only 6 lines of
portable sh
:
#!/bin/sh
COLUMNS="${COLUMNS:-$(tput cols)}"
for text in "${@:-${HR_DEFAULT_TEXT:-β}}"; do
printf '\033[?7l%*s\033[?7h' "$COLUMNS" | sed -e "s/ /$text/g"
done
exit 0
- Extremely minimum "only 6 lines of
portable sh
" - Can output multiple lines at once
- Can define custom text
- Treats multi-byte symbols properly
's default text can be change through environment variable
Note
can not be
source
or invoke from Bash, for that use Gil Gonçalves'shr
- Unix commands to process
- Option 1: using
curl
curl https://raw.githubusercontent.com/NNBnh/hr/main/bin/hr > ~/.local/bin/hr
chmod +x ~/.local/bin/hr
- Option 2: using
git
git clone https://github.com/NNBnh/hr.git ~/.local/share/hr
ln -s ~/.local/share/hr/bin/hr ~/.local/bin/hr
For Bpkg user:
bpkg install NNBnh/hr
For Basher user:
basher install NNBnh/hr
Note If you can and want to port SuperB HR to other package managers, feel free to do so.
hr [TEXTS]
Examples:
hr
this will output:
ββββββββββββββββββββββββββββββββββββββββ
You can make multiple at the same time and with any
TEXT
:
hr '#' 'hr' 'Hello world! '
this will output:
########################################
hrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhr
Hello world! Hello world! Hello world! H
is configured through environment variables:
export HR_DEFAULT_TEXT="<text>"
Special thanks to:
Made with β€οΈ by NNB