diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-10 09:04:34 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-10 09:04:34 +0200 |
commit | a28e7a9b9b2a4a45177a02f556806906e191bb8e (patch) | |
tree | 24eea9bcd087a354d152307392d6502e49337a61 /ce | |
parent | d6ca58d1a1cd10a167f0b302c73f4abfbe3388c9 (diff) | |
download | xutil-a28e7a9b9b2a4a45177a02f556806906e191bb8e.tar.gz |
Add 'ce' utility
Diffstat (limited to 'ce')
-rwxr-xr-x | ce | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -0,0 +1,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 "$@" |