-
Notifications
You must be signed in to change notification settings - Fork 2
/
.msg3
executable file
·81 lines (69 loc) · 2.17 KB
/
.msg3
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#source 'lib.trap.sh'
trap 'echo >&2 "Error - exited with status $? at line $LINENO:";
pr -tn $0 | tail -n+$((LINENO - 3)) | head -n7' ERR
function msg3()
{
usage()
{
echo "Usage: msg3 [-w|-g] [-n] message_here"
echo "(w)warning,(g)greet,(e)bad|negative|error,(o)good|okay,(b)bold,(u)underline,(l)underline+bold";
echo "(n)no-newline";
return 2;
}
set_variable()
{
local varname=$1
shift
if [ -z "${!varname}" ]; then
eval "$varname=\"$@\""
else
echo "Error: $varname already set"
usage ; return 2;
fi
}
if (( $# >= 2 )) ; then #No STDIN
echo -n ;
else #Has STDIN
MSG="$(cat -)";
set -- $1 $MSG
fi
B=`tput bold` #BOLD
D=`tput dim` #DIM
U=`tput sgr 0 1` #UNDERLINE
U2=`tput smul` #UNDERLINE2
NOU=`tput rmul` #NO UNDERLINE
H=`tput smso` #HIGHLIGHT
X=`tput sgr0` #RESET
C='tput setaf ' #COLOR
unset FORMAT NONL NL;
OPTIND=1 # This saves my life :) (again in 2019)
while getopts 'eowgbuln?h' c
do
case $c in
e) set_variable FORMAT ERR && return 0 ;;
o) set_variable FORMAT OKAY && return 0 ;;
w) set_variable FORMAT WARN ;;
g) set_variable FORMAT GREET ;;
b) set_variable FORMAT BOLD ;;
u) set_variable FORMAT ULINE ;;
l) set_variable FORMAT ULBLD ;;
n) set_variable NONL 1 ;;
h|?) usage ;; esac
done
[ -z "$FORMAT" ] && usage
#[ -z "$NONL" ] && usage
shift $((OPTIND - 1))
if [ "1" = "$NONL" ]; then
NL='-n'
fi
case $FORMAT in
ERR) echo $NL `tput setaf 1`${H}$@`tput sgr0` ;;
OKAY) echo $NL `tput setaf 2`${B}$@`tput sgr0` ;; #good
WARN) echo $NL `tput setaf 3`${H}$@`tput sgr0` ;;
GREET) echo $NL `tput setaf 6`${B}$@`tput sgr0` ;;
BOLD) echo $NL `tput bold` $@`tput sgr0` ;;
ULINE) echo $NL ${U}$@`tput sgr0` ;;
ULBLD) echo $NL `tput bold` ${U}$@`tput sgr0` ;;
esac
}