Skip to content

Commit 901faec

Browse files
mislavGeoff Harcourt
authored and
Geoff Harcourt
committed
Only colorize warning messages if stderr is a tty
This is to avoid outputting ANSI escape codes to scripts and log files.
1 parent 16219a3 commit 901faec

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

hooks/post-up

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ vim -u $HOME/.vimrc.bundles +PlugInstall +PlugClean! +qa
1010

1111
# detect old OS X broken /etc/zshenv and suggest rename
1212
if grep -qw path_helper /etc/zshenv 2>/dev/null; then
13-
fg_red=$'\e[31m'
14-
fg_bold_white=$'\e[1;37m'
15-
reset_color=$'\e[m'
13+
if [ -t 2 ]; then
14+
fg_red=$'\e[31m'
15+
fg_bold_white=$'\e[1;37m'
16+
reset_color=$'\e[m'
17+
else
18+
fg_red=""
19+
fg_bold_white=""
20+
reset_color=""
21+
fi
1622

1723
# resolve BASH_SOURCE to absolute path
1824
bash_source="$BASH_SOURCE"

zshenv

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ local _old_path="$PATH"
66
if [[ $PATH != $_old_path ]]; then
77
# `colors` isn't initialized yet, so define a few manually
88
typeset -AHg fg fg_bold
9-
fg[red]=$'\e[31m'
10-
fg_bold[white]=$'\e[1;37m'
11-
reset_color=$'\e[m'
9+
if [ -t 2 ]; then
10+
fg[red]=$'\e[31m'
11+
fg_bold[white]=$'\e[1;37m'
12+
reset_color=$'\e[m'
13+
else
14+
fg[red]=""
15+
fg_bold[white]=""
16+
reset_color=""
17+
fi
1218

1319
cat <<MSG >&2
1420
${fg[red]}Warning:${reset_color} your \`~/.zshenv.local' configuration seems to edit PATH entries.

0 commit comments

Comments
 (0)