aboutsummaryrefslogtreecommitdiff
path: root/ce
blob: 08550aa006872bd88d87c640399a0882a7765410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/sh

# ce -- center text

usage() { echo usage: $0 [-cols] text ... 1>&2; exit 1; }

case "$1" in
-*)	cols=${1#-}
	[ "$cols" -gt 0 ] || usage
	shift ;;
*)	cols=`tput cols`
	[ "$cols" -le 80 ] || cols=80
	;;
esac

[ $# -gt 0 ] || usage
len=`echo "$@" | wc -c`
max=$(((cols - len) / 2))
i=0
while [ $((i++)) -lt $max ]; do
	printf ' '
done
echo "$@"