From 387425e2b20b2dce03e1a9e857b0ffd83ad5df7e Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Wed, 17 Feb 2021 22:13:18 +0000 Subject: [PATCH] Use BASH instead of grep(1) Much like my previous commit, grep(1) isn't needed here at all. BASH can handle REGEX as well as glob pattern matching in a very similar way. In this commit, I've made use of a `while read` loop to achieve the same thing as before, but much more efficiently. If it turns out that the `rbenv` command usually returns a crap ton of data (10s of thousands of lines, at _least_), then please ignore this commit. --- themes/base.theme.bash | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 1c4e0c4c..1f9f0b35 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -281,7 +281,7 @@ function git_prompt_vars { SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo "") + SCM_CHANGE=$(_git-short-sha 2> /dev/null || echo) } function p4_prompt_vars { @@ -391,7 +391,17 @@ function rvm_version_prompt { function rbenv_version_prompt { if which rbenv &> /dev/null; then rbenv=$(rbenv version-name) || return - rbenv commands | grep -q gemset && gemset=$(rbenv gemset active 2> /dev/null) && rbenv="$rbenv@${gemset%% *}" + + while read; do + if [[ $REPLY == *gemset* ]]; then + if gemset=$(rbenv gemset active 2> /dev/null); then + rbenv="$rbenv@${gemset%% *}" + fi + + break + fi + done <<< "$(rbenv commands)" + if [ "$rbenv" != "system" ]; then echo -e "$RBENV_THEME_PROMPT_PREFIX$rbenv$RBENV_THEME_PROMPT_SUFFIX" fi