blob: 69d9e114c725a22fb155bbf245547bbb910a27ba (
plain)
1 #!/usr/bin/env bash
2 # Pkgself builds self-extracting installers
3 # Copyright (C) 2018 Aaron Ball <nullspoon@oper.io>
4 #
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18 set -e
19
20 #
21 # Useful color codes
22 #
23 # Normal colors
24 export CRED="$(printf '\033[0;31m')"
25 export CGREEN="$(printf '\033[0;32m')"
26 export CYELLOW="$(printf '\033[0;33m')"
27 export CBLUE="$(printf '\033[0;34m')"
28 export CMAGENTA="$(printf '\033[0;35m')"
29 export CCYAN="$(printf '\033[0;36m')"
30 export CGREY="$(printf '\033[0;37m')"
31 export CWHITE="$(printf '\033[0;38m')"
32 export CRESET="$(printf '\033[0m')"
33 # Bold colors
34 export CBRED="$(printf '\033[1;31m')"
35 export CBGREEN="$(printf '\033[1;32m')"
36 export CBYELLOW="$(printf '\033[1;33m')"
37 export CBBLUE="$(printf '\033[1;34m')"
38 export CBMAGENTA="$(printf '\033[1;35m')"
39 export CBCYAN="$(printf '\033[1;36m')"
40 export CBGREY="$(printf '\033[1;37m')"
41 export CBWHITE="$(printf '\033[1;38m')"
42
43
44 # colorize:
45 # @color Escape sequence to color text with
46 #
47 # Colors the text from stdin with the specified color escape sequence.
48 # NOTE: Resets escape sequence at the end of each line
49 #
50 # Returns 0 always
51 colorize() {
52 local color="${1}"
53 # If the tty is a terminal, support color
54 if [ -t 1 ]; then
55 sed -e "s/^/${color}/" -e "s/$/${CRESET}/"
56 return 0
57 fi
58 # Tty is not a teriminal, print without color support
59 cat
60 }
|