Skip to content

Commit

Permalink
make script posix compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
txgk committed May 25, 2022
1 parent 3771db2 commit 6b3696e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
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 -e "s/ /$1/g" -e "s/.//$((COLS + 1))g"
}

hrs() {
local WORD

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

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

0 comments on commit 6b3696e

Please sign in to comment.