Only colorize warning messages if stderr is a tty
This is to avoid outputting ANSI escape codes to scripts and log files.
This commit is contained in:
parent
16219a31db
commit
901faec464
2 changed files with 18 additions and 6 deletions
|
@ -10,9 +10,15 @@ vim -u $HOME/.vimrc.bundles +PlugInstall +PlugClean! +qa
|
||||||
|
|
||||||
# detect old OS X broken /etc/zshenv and suggest rename
|
# detect old OS X broken /etc/zshenv and suggest rename
|
||||||
if grep -qw path_helper /etc/zshenv 2>/dev/null; then
|
if grep -qw path_helper /etc/zshenv 2>/dev/null; then
|
||||||
fg_red=$'\e[31m'
|
if [ -t 2 ]; then
|
||||||
fg_bold_white=$'\e[1;37m'
|
fg_red=$'\e[31m'
|
||||||
reset_color=$'\e[m'
|
fg_bold_white=$'\e[1;37m'
|
||||||
|
reset_color=$'\e[m'
|
||||||
|
else
|
||||||
|
fg_red=""
|
||||||
|
fg_bold_white=""
|
||||||
|
reset_color=""
|
||||||
|
fi
|
||||||
|
|
||||||
# resolve BASH_SOURCE to absolute path
|
# resolve BASH_SOURCE to absolute path
|
||||||
bash_source="$BASH_SOURCE"
|
bash_source="$BASH_SOURCE"
|
||||||
|
|
12
zshenv
12
zshenv
|
@ -6,9 +6,15 @@ local _old_path="$PATH"
|
||||||
if [[ $PATH != $_old_path ]]; then
|
if [[ $PATH != $_old_path ]]; then
|
||||||
# `colors` isn't initialized yet, so define a few manually
|
# `colors` isn't initialized yet, so define a few manually
|
||||||
typeset -AHg fg fg_bold
|
typeset -AHg fg fg_bold
|
||||||
fg[red]=$'\e[31m'
|
if [ -t 2 ]; then
|
||||||
fg_bold[white]=$'\e[1;37m'
|
fg[red]=$'\e[31m'
|
||||||
reset_color=$'\e[m'
|
fg_bold[white]=$'\e[1;37m'
|
||||||
|
reset_color=$'\e[m'
|
||||||
|
else
|
||||||
|
fg[red]=""
|
||||||
|
fg_bold[white]=""
|
||||||
|
reset_color=""
|
||||||
|
fi
|
||||||
|
|
||||||
cat <<MSG >&2
|
cat <<MSG >&2
|
||||||
${fg[red]}Warning:${reset_color} your \`~/.zshenv.local' configuration seems to edit PATH entries.
|
${fg[red]}Warning:${reset_color} your \`~/.zshenv.local' configuration seems to edit PATH entries.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue