-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.sh
24 lines (22 loc) · 831 Bytes
/
color.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Avoid bash errors about undeclared variables
declare color_none= color_bold= color_red= color_green= color_yellow= color_blue=
# Enable colored output in terminal
enable_colors() {
if [[ -t 1 && -t 2 ]]; then
if tput setaf 0 &> /dev/null; then
color_none=$(tput sgr0)
color_bold=$(tput bold)
color_red=${color_bold}$(tput setaf 1)
color_green=${color_bold}$(tput setaf 2)
color_yellow=${color_bold}$(tput setaf 3)
color_blue=${color_bold}$(tput setaf 4)
else
color_none="\e[1;0m"
color_bold="\e[1;1m"
color_red="${color_bold}\e[1;31m"
color_green="${color_bold}\e[1;32m"
color_yellow="${color_bold}\e[1;33m"
color_blue="${color_bold}\e[1;34m"
fi
fi
}