NNBnh / hr

πŸ“ Portable horizontal ruler for terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Portable horizontal ruler for terminal

License: GPL-3.0 Development completed

πŸ’‘ About

hr (SuperB HR) is a CLI tool written in portable sh to render horizontal ruler/line in the terminal.

πŸ“” Story

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 hr 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

✨ Features

  • Extremely minimum "only 6 lines of portable sh"
  • Can output multiple lines at once
  • Can define custom text
  • Treats multi-byte symbols properly
  • hr's default text can be change through environment variable

Note hr can not be source or invoke from Bash, for that use Gil Gonçalves's hr

πŸš€ Setup

🧾 Dependencies

πŸ“₯ Installation

πŸ”§ Manually

  • 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

πŸ“¦ Package manager

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.

⌨️ Usage

Run hr in the terminal:

hr [TEXTS]

Examples:

hr

this will output:

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

You can make multiple hr at the same time and with any TEXT:

hr '#' 'hr' 'Hello world! '

this will output:

########################################
hrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhr
Hello world! Hello world! Hello world! H

βš™οΈ Configuration

hr is configured through environment variables:

export HR_DEFAULT_TEXT="<text>"

πŸ’Œ Credits

Special thanks to:






Made with ❀️ by NNB

Buy Me a Coffee

About

πŸ“ Portable horizontal ruler for terminal

License:GNU General Public License v3.0


Languages

Language:Shell 78.1%Language:Makefile 21.9%