Fixed(?) RVM gem list helper #411

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
Contributor

jbhannah commented Jun 6, 2011

Using the gems command from the RVM plugin on Ubuntu 11.04 was not working correctly—all it would do was show the GNU sed help output. Some playing around showed that the repeated -E option was causing that to happen, so removing all -Es after the first one returned what appears to be the correct output. I don't remember this same problem occurring on my Mac (latest 10.6, zsh from brew), and I don't have it with me to test this or to see if the output is the same as what it's supposed to be originally, but this does at least fix the radically unexpected behavior when using GNU sed in Ubuntu 11.04.

@jbhannah jbhannah commented on the diff Jun 6, 2011

plugins/rvm/rvm.plugin.zsh
@@ -36,9 +36,9 @@ function gems {
local current_ruby=`rvm-prompt i v p`
local current_gemset=`rvm-prompt g`
- gem list $@ | sed \
- -Ee "s/\([0-9\.]+( .+)?\)/$fg[blue]&$reset_color/g" \
- -Ee "s|$(echo $rvm_path)|$fg[magenta]\$rvm_path$reset_color|g" \
- -Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
- -Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
+ gem list $@ | sed -E \
@jbhannah

jbhannah Jun 6, 2011

Contributor

The question is, does a single -E here apply to all following -e expressions?

@betawaffle

betawaffle Jun 6, 2011

Contributor

The -E is for OS X, If you can make this work on both I'd be happy.

@jbhannah

jbhannah Jun 7, 2011

Contributor

GNU sed does actually support -E for legacy reasons, but its normal equivalent is -r. We can either leave -E there, or set an options variable depending on the version of sed (BSD or GNU). I'll look into it.

Contributor

jbhannah commented Jun 6, 2011

For what it's worth, piping each expression's output into a separate sed -Ee command generates the same output as this diff; and in both cases, gem versions with letters (rails (3.1.0.rc1), for example) are not highlighted. I'll make a separate commit in this branch, either now or in a separate pull request, to try to fix this.

jbhannah closed this Jun 6, 2011

jbhannah reopened this Jun 6, 2011

Contributor

betawaffle commented Jun 6, 2011

Yes, this function is by far not complete. Improving it would be helpful.

Contributor

jbhannah commented Jun 7, 2011

I've tested the original version on OS X, and its output is (AFAICT) the same as the output of the modified script here. Next is to see if the modified script works with BSD sed.

Contributor

betawaffle commented Jun 7, 2011

That's good, thanks! I have also made a change to this in my version to fix a couple issues with it.

function gems {
    local current_ruby=`rvm-prompt i v p`
    local current_gemset=`rvm-prompt g`

    gem list $@ | sed \
        -Ee "s/\([0-9\.]+(,? .+)?\)/$fg[blue]&$reset_color/g" \
        -Ee "s|$(echo $rvm_path)|$fg[magenta]\$rvm_path$reset_color|g" \
        -Ee "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
        -Ee "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
}

I added ,? before the .+ to match multiple versions of a gem. So, updated would look like this:

function gems {
    local current_ruby=`rvm-prompt i v p`
    local current_gemset=`rvm-prompt g`

    gem list $@ | sed -E \
        -e "s/\([0-9\.]+(,? .+)?\)/$fg[blue]&$reset_color/g" \
        -e "s|$(echo $rvm_path)|$fg[magenta]\$rvm_path$reset_color|g" \
        -e "s/$current_ruby@global/$fg[yellow]&$reset_color/g" \
        -e "s/$current_ruby$current_gemset$/$fg[green]&$reset_color/g"
}
Contributor

jbhannah commented Feb 2, 2013

Closing, re-forking and re-submitting this to be based on a more current version of the code, since this problem still occurs in Ubuntu.

jbhannah closed this Feb 2, 2013

@vguerci vguerci pushed a commit to vguerci/oh-my-zsh that referenced this pull request Aug 11, 2013

@sorin-ionescu sorin-ionescu [Fix #411] Add Homebrew module 9d504d2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment