-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwh
84 lines (81 loc) · 3.03 KB
/
wh
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
82
83
84
#!/bin/bash
set -e
usage () {
echo
echo "Aufruf: wh --forecolor <color> --backcolor <color> \"Text\""
echo
echo "Gibt Text (mehr)farbig auf der Konsole aus. "
echo
echo -e "\e[4mOption:\e[0m"
echo
echo " -f --forecolor Vordergrundfarbe setzen (kann mehrfach angegebn werden). "
echo " -b --backcolor Hintergrundfarbe setzen (kann mehrfach angegebn werden). "
echo " -h --help Ruft diese Hilfe auf. "
echo
echo -e "\e[4mBeispiel:\e[0m"
echo
echo " wh -f green \"Dies ist\" -f red \"ein Beispiel\n\" -b white -f blue \"mit Zeilenumbruch\""
echo
echo -e "\e[4mErgebnis:\e[0m"
echo
echo -e " \e[0;32mDies ist \e[0;31mein Beispiel\n \e[0;34m\e[1;47mmit Zeilenumbruch\e[0m"
echo
}
FC=0
BC=0
while test $# -gt 0;do
OPT=$1
shift
case $OPT in
-f | --forecolor)
case ${1,,} in
black) FC="30"; shift;;
red) FC="31"; shift;;
green) FC="32"; shift;;
orange) FC="33"; shift;;
blue) FC="34"; shift;;
purple) FC="35"; shift;;
cyan) FC="36"; shift;;
lgray | lightgray) FC="37"; shift;;
dgray | darkgray) FC="90"; shift;;
lred | lightred) FC="91"; shift;;
lgreen | lightgreen) FC="92"; shift;;
yellow) FC="93"; shift;;
lblue | lightblue) FC="94"; shift;;
lpurple | lightpurple) FC="95"; shift;;
lcyan | lightcyan) FC="96"; shift;;
white) FC="97"; shift;;
nc | nocolor | none) FC="39" ; shift;;
*) shift;;
esac
;;
-b | --backcolor)
case ${1,,} in
black) BC="40"; shift;;
red) BC="41"; shift;;
green) BC="42"; shift;;
orange) BC="43"; shift;;
blue) BC="44"; shift;;
purple) BC="45"; shift;;
cyan) BC="46"; shift;;
lgray | lightgray) BC="47"; shift;;
dgray | darkgray) BC="100"; shift;;
lred | lightred) BC="101"; shift;;
lgreen | lightgreen) BC="102"; shift;;
yellow) BC="103"; shift;;
lblue | lightblue) BC="104"; shift;;
lpurple | lightpurple) BC="105"; shift;;
lcyan | lightcyan) BC="106"; shift;;
white) BC="107"; shift;;
nc | nocolor | none) BC="49" ; shift;;
*) shift;;
esac
;;
-h | --help)
usage
exit 0
;;
*) if [[ $# -gt 0 && ! "$OPT" =~ .*\n$ ]];then ECHO="$ECHO\e[${FC};${BC}m$OPT ";else ECHO="$ECHO\e[${FC};${BC}m$OPT";fi;;
esac
done
echo -e "$ECHO\e[0m"