An open API service indexing awesome lists of open source software.

https://github.com/nnbnh/hr

πŸ“ Portable horizontal ruler for terminal
https://github.com/nnbnh/hr

basher bpkg cli hr posix terminal

Last synced: 6 months ago
JSON representation

πŸ“ Portable horizontal ruler for terminal

Awesome Lists containing this project

README

          


Portable horizontal ruler for terminal



License: GPL-3.0
Development completed

## πŸ’‘ About

![`hr`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png) (SuperB HR) is a CLI tool written in [`portable sh`](https://github.com/dylanaraps/pure-sh-bible) to render horizontal ruler/line in the terminal.

### πŸ“” Story

Recently, i'm obsessed with [`hr`](https://github.com/LuRsT/hr) and i want a portable shell `hr`, the best i found is *"`POSIX`-ish Way"* from the blog [Alternatives to the `hr` library](https://grayson.sh/blogs/some-alternatives-to-hr):

```sh
printf '%*s' "$(tput cols)" | tr ' ' "${*:-#}"
```

but it lacks [Gil GonΓ§alves's `hr`](https://github.com/LuRsT/hr) key features like output multiple line, custom text or even treats multi-byte symbols properly. So i decided to create ![`hr`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png) based on the blog's method with only **6 lines** of [`portable sh`](https://github.com/dylanaraps/pure-sh-bible):

```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`](https://github.com/dylanaraps/pure-sh-bible)"*
- Can output **multiple lines** at once
- Can define **custom text**
- Treats **multi-byte symbols** properly
- ![`hr`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png)'s default text can be change through [environment variable](#%EF%B8%8F-configuration)

> **Note** *![`hr`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png) can not be `source` or invoke from [Bash](https://www.gnu.org/software/bash), for that use [Gil GonΓ§alves's `hr`](https://github.com/LuRsT/hr)*

## πŸš€ Setup

### 🧾 Dependencies

- [Unix commands](https://en.wikipedia.org/wiki/List_of_Unix_commands) to process

### πŸ“₯ Installation

#### πŸ”§ Manually

- Option 1: using `curl`

```sh
curl https://raw.githubusercontent.com/NNBnh/hr/main/bin/hr > ~/.local/bin/hr
chmod +x ~/.local/bin/hr
```

- Option 2: using `git`

```sh
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](https://github.com/bpkg/bpkg) user:

```sh
bpkg install NNBnh/hr
```

For [Basher](https://github.com/basherpm/basher) user:

```sh
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`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png) in the terminal:

```sh
hr [TEXTS]
```

Examples:

```sh
hr
```

this will output:

```console
────────────────────────────────────────
```

You can make multiple ![`hr`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png) at the same time and with any `TEXT`:

```sh
hr '#' 'hr' 'Hello world! '
```

this will output:

```console
########################################
hrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhrhr
Hello world! Hello world! Hello world! H
```

## βš™οΈ Configuration

![`hr`](https://user-images.githubusercontent.com/43980777/109386947-cd054d80-7930-11eb-90b3-49836d184f25.png) is configured through environment variables:

```sh
export HR_DEFAULT_TEXT=""
```

## πŸ’Œ Credits

Special thanks to:
- [**hr**](https://github.com/LuRsT/hr) by [Gil GonΓ§alves](https://github.com/LuRsT)
- [**Alternatives to the 'hr' library**](https://grayson.sh/blogs/some-alternatives-to-hr) by [Grayson Kent](https://grayson.sh)





---

>

Made with ❀️ by NNB


>
>

Buy Me a Coffee