Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # center - center a group of lines |
| 4 | # |
| 5 | # tabs in the lines might cause this to look a little bit off |
| 6 | # |
| 7 | # |
Chet Ramey | ac50fba | 2014-02-26 09:36:43 -0500 | [diff] [blame] | 8 | # Chet Ramey <chet.ramey@case.edu> |
| 9 | # |
| 10 | # Copyright 1999 Chester Ramey |
| 11 | # |
| 12 | # This program is free software; you can redistribute it and/or modify |
| 13 | # it under the terms of the GNU General Public License as published by |
| 14 | # the Free Software Foundation; either version 2, or (at your option) |
| 15 | # any later version. |
| 16 | # |
| 17 | # TThis program is distributed in the hope that it will be useful, |
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | # GNU General Public License for more details. |
| 21 | # |
| 22 | # You should have received a copy of the GNU General Public License |
| 23 | # along with this program; if not, write to the Free Software Foundation, |
| 24 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 25 | |
| 26 | width=${COLUMNS:-80} |
| 27 | |
| 28 | if [[ $# == 0 ]] |
| 29 | then |
| 30 | set -- /dev/stdin |
| 31 | fi |
| 32 | |
| 33 | for file |
| 34 | do |
| 35 | while read -r |
| 36 | do |
| 37 | printf "%*s\n" $(( (width+${#REPLY})/2 )) "$REPLY" |
| 38 | done < $file |
| 39 | done |
| 40 | |
| 41 | exit 0 |