Skip to content

Commit a83677f

Browse files
install: add option to suppress color
Signed-off-by: Matt Hoosier <[email protected]>
1 parent 3b9f0e8 commit a83677f

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

install

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# POSIX
2121

2222
next=0
23+
no_color=0
2324
verbose=0
2425
version=1.8.1.2
2526

@@ -36,6 +37,7 @@ install --prefix /usr/local
3637
Options:
3738
--prefix/-P: base bath where all files will be deployed (default /usr/local if root, ~/.local if not)
3839
--next/-N: install latest development version from git, instead of the latest stable release.
40+
--no-color: disable color formatting
3941
--help/-h: show this message
4042
-v: show more verbosity
4143
EOF
@@ -49,6 +51,10 @@ while :; do
4951
show_help
5052
exit
5153
;;
54+
--no-color)
55+
shift
56+
no_color=1
57+
;;
5258
-v | --verbose)
5359
shift
5460
verbose=1
@@ -69,6 +75,17 @@ while :; do
6975
esac
7076
done
7177

78+
# if we're in not a tty, don't use colors
79+
BOLD_GREEN=""
80+
BOLD_RED=""
81+
CLEAR=""
82+
if [ -t 0 ] && [ -t 1 ] && [ "${no_color}" -ne 1 ]; then
83+
# we're in a tty, use colors
84+
BOLD_GREEN='\033[1;32m'
85+
BOLD_RED='\033[1;31m'
86+
CLEAR='\033[0m'
87+
fi
88+
7289
if [ -z "${prefix}" ]; then
7390
prefix="/usr/local"
7491
# in case we're not root, just default to the home directory
@@ -131,7 +148,7 @@ if [ -e "${curr_dir}/distrobox-enter" ]; then
131148
done
132149
fi
133150
else
134-
printf >&2 "\033[1;31m Checking dependencies...\n\033[0m"
151+
printf >&2 "${BOLD_RED} Checking dependencies...\n${CLEAR}"
135152
# check that we have base dependencies
136153
if ! {
137154
command -v curl > /dev/null || command -v wget > /dev/null
@@ -147,7 +164,7 @@ else
147164
download="wget -qO"
148165
fi
149166

150-
printf >&2 "\033[1;31m Downloading...\n\033[0m"
167+
printf >&2 "${BOLD_RED} Downloading...\n${CLEAR}"
151168
if [ "${next}" -eq 0 ]; then
152169
release_ver="89luca89/distrobox/archive/refs/tags/${version}.tar.gz"
153170
release_name=$(basename "${release_ver}")
@@ -161,7 +178,7 @@ else
161178
# download our target
162179
${download} "${release_name}" "https://github.com/${release_ver}"
163180
# uncompress
164-
printf >&2 "\033[1;31m Unpacking...\n\033[0m"
181+
printf >&2 "${BOLD_RED} Unpacking...\n${CLEAR}"
165182
if [ "${verbose}" -ne 0 ]; then
166183
tar xvf "${release_name}"
167184
else
@@ -214,10 +231,10 @@ fi
214231
[ ! -w "${dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${dest_path}" && exit 1
215232
[ ! -w "${man_dest_path}" ] && printf >&2 "Cannot write into %s, permission denied.\n" "${man_dest_path}" && exit 1
216233

217-
printf >&2 "\033[1;32m Installation successful!\n\033[0m"
218-
printf >&2 "\033[0m Shell scripts are located in \033[1;31m%s\n\033[0m" "${dest_path}"
219-
printf >&2 "\033[0m Manpages are located in \033[1;31m%s\n\033[0m" "${man_dest_path}"
234+
printf >&2 "${BOLD_GREEN} Installation successful!\n${CLEAR}"
235+
printf >&2 "${CLEAR} Shell scripts are located in ${BOLD_RED}%s\n${CLEAR}" "${dest_path}"
236+
printf >&2 "${CLEAR} Manpages are located in ${BOLD_RED}%s\n${CLEAR}" "${man_dest_path}"
220237

221238
if ! echo "${PATH}" | grep -q "${dest_path}"; then
222-
printf >&2 "\033[0m Be sure that \033[1;31m%s\033[0m is in your \033[1;31m\$PATH\033[0m environment variable to be able to use distrobox without specifying the full path.\n\033[0m" "${dest_path}"
239+
printf >&2 "${CLEAR} Be sure that ${BOLD_RED}%s${CLEAR} is in your ${BOLD_RED}\$PATH${CLEAR} environment variable to be able to use distrobox without specifying the full path.\n${CLEAR}" "${dest_path}"
223240
fi

uninstall

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
# POSIX
2121

22+
no_color=0
2223
verbose=0
2324

2425
# Print usage to stdout.
@@ -32,6 +33,7 @@ show_help()
3233
uninstall --prefix /usr/local
3334
3435
Options:
36+
--no-color: disable color formatting
3537
--prefix/-P: base bath where all files will be deployed (default /usr/local if root, ~/.local if not)
3638
--help/-h: show this message
3739
-v: show more verbosity
@@ -46,6 +48,10 @@ while :; do
4648
show_help
4749
exit
4850
;;
51+
--no-color)
52+
shift
53+
no_color=1
54+
;;
4955
-v | --verbose)
5056
shift
5157
verbose=1
@@ -69,6 +75,17 @@ while :; do
6975
esac
7076
done
7177

78+
# if we're in not a tty, don't use colors
79+
BOLD_GREEN=""
80+
BOLD_RED=""
81+
CLEAR=""
82+
if [ -t 0 ] && [ -t 1 ] && [ "${no_color}" -ne 1 ]; then
83+
# we're in a tty, use colors
84+
BOLD_GREEN='\033[1;32m'
85+
BOLD_RED='\033[1;31m'
86+
CLEAR='\033[0m'
87+
fi
88+
7289
if [ -z "${prefix}" ]; then
7390
prefix="/usr/local"
7491
# in case we're not root, just default to the home directory
@@ -104,6 +121,6 @@ done
104121
[ -e "${icon_dest_path}"/terminal-distrobox-icon.svg ] && rm "${icon_dest_path}"/terminal-distrobox-icon.svg
105122
[ -e "${icon_dest_path}"/distrobox ] && rm -rf "${icon_dest_path}"/distrobox
106123

107-
printf >&2 "\033[1;32m Thank you for using Distrobox. Uninstall complete.\n\033[0m"
108-
printf >&2 "\033[0m Removed shell scripts located in \033[1;31m%s\n\033[0m" "${dest_path}"
109-
printf >&2 "\033[0m Removed manpages located in \033[1;31m%s\n\033[0m" "${man_dest_path}"
124+
printf >&2 "${BOLD_GREEN} Thank you for using Distrobox. Uninstall complete.\n${CLEAR}"
125+
printf >&2 "${CLEAR} Removed shell scripts located in ${BOLD_RED}%s\n${CLEAR}" "${dest_path}"
126+
printf >&2 "${CLEAR} Removed manpages located in ${BOLD_RED}%s\n${CLEAR}" "${man_dest_path}"

0 commit comments

Comments
 (0)