aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/unix/center_text.sh
blob: 6e3b9b21a566e2c55cc81b79b58a613bd73a009b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#! /bin/bash

echo '\e[5 q'

while read -r -e text; do
  tput cuu1 civis

  width="$(tput cols)"
  left=$(( ($width - ${#text}) /2 ))
  right=$(( $width - $left - ${#text} ))

  echo -en '\r'
  eval "printf ' %.0s' {1..$left}"
  echo -n $text
  eval "printf ' %.0s' {1..$right}"
done