Skip to content

Commit

Permalink
Merge branch 'multiple-arguments' of github.com:Keith-S-Thompson/hr i…
Browse files Browse the repository at this point in the history
…nto Keith-S-Thompson-multiple-arguments

Conflicts:
	README.md
	hr
  • Loading branch information
LuRsT committed Feb 11, 2014
2 parents 53fca12 + 1e404d4 commit 103e25c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Use the old `<hr />` tag, but in your terminal. How? Allow me to explain:
## Setup

$ curl https://raw.github.com/LuRsT/hr/master/hr > ~/bin/hr
(Examine ~/bin/hr)
$ chmod +x ~/bin/hr

Note: You should have `~/bin` in your `$PATH` for this to work.
Expand All @@ -27,13 +28,17 @@ Note: You should have `~/bin` in your `$PATH` for this to work.
********************************** # Till the end of your terminal window
$

You can also make "beautiful" ascii patterns
You can also make "beautiful" ASCII patterns

$ hr -#-
$ hr - # -
----------------------------------
##################################
----------------------------------
$
$ hr '-#-' '-' '-#-'
-#--#--#--#--#--#--#--#--#--#--#--
----------------------------------
-#--#--#--#--#--#--#--#--#--#--#--


That's it, no requirements, just pure old `bash` and `tput`, check the source,
it's free.
Expand Down
23 changes: 13 additions & 10 deletions hr
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,23 @@


function hr {
space_character="$1"
columns="$(tput cols)"

printf "%${columns}s\n" | tr " " "$space_character"
word="$1"
line=''
while [[ ${#line} -lt $columns ]]; do
line="$line$word"
done
echo "${line:0:$columns}"
}


if [[ -n "$1" ]]; then
space_string="$1"
string_size=${#space_string};
columns="$(tput cols)"
if [[ "$columns" -lt 0 ]] ; then
columns=80
fi

for (( char_index=0; char_index<${string_size}; char_index++ ))
do
hr "${space_string:char_index:1}"
if [[ $# > 0 ]]; then
for word in "$@" ; do
hr "$word"
done
else
hr "#"
Expand Down

0 comments on commit 103e25c

Please sign in to comment.