Skip to content

Commit

Permalink
Handle multi-letter words and multiple command-line arguments.
Browse files Browse the repository at this point in the history
Fall back to 80 columns if `tput cols` fails.
  • Loading branch information
Keith-S-Thompson committed Feb 11, 2014
1 parent f3365f8 commit 0aca6c2
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions hr
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,24 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


columns="$(tput cols)"
if [[ "$columns" -lt 0 ]] ; then
columns=80
fi

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

for (( i=1; i<columns; i++ ))
do
line+="${space_character}"
while [[ ${#line} -lt $columns ]]; do
line="$line$word"
done

echo "$line"
echo "${line:0:$columns}"
}


if [[ -n "$1" ]]; then
space_string="$1"
string_size=${#space_string};

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

0 comments on commit 0aca6c2

Please sign in to comment.