From 8fa8b0634935063fcb73bbf6ffdc2f17cbc00d5d Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 2 Feb 2016 14:15:41 +0100 Subject: [PATCH] only use colors if stdout is a terminal --- bin/autojump.bash | 6 +++++- bin/autojump.zsh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/autojump.bash b/bin/autojump.bash index 0c49d75..a7c8fdd 100644 --- a/bin/autojump.bash +++ b/bin/autojump.bash @@ -61,7 +61,11 @@ j() { output="$(autojump ${@})" if [[ -d "${output}" ]]; then - echo -e "\\033[31m${output}\\033[0m" + if [ -t 1 ]; then # if stdout is a terminal, use colors + echo -e "\\033[31m${output}\\033[0m" + else + echo -e "${output}" + fi cd "${output}" else echo "autojump: directory '${@}' not found" diff --git a/bin/autojump.zsh b/bin/autojump.zsh index fbc0960..25d50ee 100644 --- a/bin/autojump.zsh +++ b/bin/autojump.zsh @@ -52,7 +52,11 @@ j() { setopt localoptions noautonamedirs local output="$(autojump ${@})" if [[ -d "${output}" ]]; then - echo -e "\\033[31m${output}\\033[0m" + if [ -t 1 ]; then # if stdout is a terminal, use colors + echo -e "\\033[31m${output}\\033[0m" + else + echo -e "${output}" + fi cd "${output}" else echo "autojump: directory '${@}' not found"