Skip to content

Commit

Permalink
fix: fix grep unknown option: --color (#1206)
Browse files Browse the repository at this point in the history
fix #1066
  • Loading branch information
Runrioter committed Sep 21, 2022
1 parent f40a047 commit 540a17a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/utils.zsh
Expand Up @@ -232,3 +232,14 @@ spaceship::datafile() {
# todo: grep by regexp?
return 1
}

# grep with --color=never or not
# USAGE:
# spaceship::grep [options] [pattern] [file ...]
spaceship::grep() {
local GREP_OPTIONS=""
if command grep --color=never "" &>/dev/null <<< ""; then
GREP_OPTIONS="--color=never"
fi
command grep $GREP_OPTIONS "$@"
}
2 changes: 1 addition & 1 deletion sections/elixir.zsh
Expand Up @@ -39,7 +39,7 @@ spaceship_elixir() {

if [[ $elixir_version == "" ]]; then
spaceship::exists elixir || return
elixir_version=$(elixir -v 2>/dev/null | grep "Elixir" --color=never | cut -d ' ' -f 2)
elixir_version=$(elixir -v 2>/dev/null | spaceship::grep "Elixir" | cut -d ' ' -f 2)
fi

[[ $elixir_version == "system" ]] && return
Expand Down
2 changes: 1 addition & 1 deletion sections/julia.zsh
Expand Up @@ -29,7 +29,7 @@ spaceship_julia() {

spaceship::exists julia || return

local julia_version=$(julia --version | grep --color=never -oE '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]')
local julia_version=$(julia --version | spaceship::grep -oE '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]')

spaceship::section \
--color "$SPACESHIP_JULIA_COLOR" \
Expand Down
2 changes: 1 addition & 1 deletion sections/php.zsh
Expand Up @@ -29,7 +29,7 @@ spaceship_php() {

spaceship::exists php || return

local php_version=$(php -v 2>&1 | \grep --color=never -oe "^PHP\s*[0-9.]\+" | awk '{print $2}')
local php_version=$(php -v 2>&1 | spaceship::grep -oe "^PHP\s*[0-9.]\+" | awk '{print $2}')

spaceship::section \
--color "$SPACESHIP_PHP_COLOR" \
Expand Down

0 comments on commit 540a17a

Please sign in to comment.