aboutsummaryrefslogtreecommitdiff
path: root/ce
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-10 09:04:34 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-10 09:04:34 +0200
commita28e7a9b9b2a4a45177a02f556806906e191bb8e (patch)
tree24eea9bcd087a354d152307392d6502e49337a61 /ce
parentd6ca58d1a1cd10a167f0b302c73f4abfbe3388c9 (diff)
downloadxutil-a28e7a9b9b2a4a45177a02f556806906e191bb8e.tar.gz
Add 'ce' utility
Diffstat (limited to 'ce')
-rwxr-xr-xce23
1 files changed, 23 insertions, 0 deletions
diff --git a/ce b/ce
new file mode 100755
index 0000000..08550aa
--- /dev/null
+++ b/ce
@@ -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 "$@"