Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make script posix compliant #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
make script posix compliant
  • Loading branch information
txgk committed May 25, 2022
commit 78ca6ceeeed5b37229e7d6adbce49fd5b8abf89e
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ You can also make "beautiful" ASCII patterns
-#--#--#--#--#--#--#--#--#--#--#--


That's it, no requirements, just pure old `bash` and `tput`, check the source,
That's it, no requirements, just pure old POSIX shell and `tput`, check the source,
it's free.

## More
Expand Down
19 changes: 6 additions & 13 deletions hr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

# The MIT License (MIT)
#
Expand All @@ -22,30 +22,23 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

COLS="$(tput cols)"
if (( COLS <= 0 )) ; then
if [ "$COLS" -le 0 ] ; then
COLS="${COLUMNS:-80}"
fi

hr() {
local WORD="$1"
local LINE=''

if [[ -z "$WORD" ]] ; then
return;
if [ -z "$1" ] ; then
return
fi

printf -v LINE '%*s' "$COLS"
LINE="${LINE// /${WORD}}"
echo "${LINE:0:${COLS}}"
printf '%*s' "$COLS" ' ' | sed "s/ /$1/g" | grep -o "^.\{$COLS\}"
}

hrs() {
local WORD

for WORD in "${@:-#}"
do
hr "$WORD"
done
}

[ "$0" == "$BASH_SOURCE" ] && hrs "$@"
hrs "$@"