File: textutils.sh

package info (click to toggle)
cron 3.0pl1-206
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,848 kB
  • sloc: ansic: 54,879; xml: 1,612; perl: 733; sh: 649; makefile: 450; python: 43
file content (38 lines) | stat: -rw-r--r-- 739 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# textutils.sh: this file can be sourced in shell scripts

# function frame
# usage:
#        frame "abcd efgh" ij
# yields:
# +-------------+
# |  abcd efgh  |
# |  ij         |
# +-------------+
frame(){
    content=""
    maxlen=0
    while [ -n "$1" ]; do
	content="${content}|:$1:|\n"
	len=${#1}
	if [ $maxlen -lt $len ]; then
	    maxlen=$len
	fi
	shift
    done
    l=+$(seq $(( maxlen + 4 )) | sed 's/.*/-/'| tr -d "\n")+
    echo $l
    printf "${content}" | column -t -s ":"
    echo $l
}

# function abort
# stops the script and exits with non-zero status
#
# if a parameter is provided, call the function frame with it
#  and redirect the result to stderr
abort(){
    if [ -n "$1" ]; then
	frame "$1" 1>&2
    fi
    exit 1
}