When in `brew edit`, can't execute the lolcat ruby gem, even though it is found


#1

Hi! So, this is a weird issue I’m having with Homebrew that I can’t quite figure out. My $EDITOR is set to ed, which I have as a custom shell script that runs ged (GNU ed installed with Homebrew) through lolcat, a Ruby gem that colors the text. Using my ed script works perfectly in most situations. However, when I run brew edit, I get an error that lolcat can’t be found. I thought it was an environment/PATH issue, between my own env and the env while in brew edit. However, that doesn’t seem to be the case, because when editing, lolcat is found but won’t execute. Does anyone know how I can fix this? It’s only an issue while trying to brew edit.

It might be easier to just show an example bash session with context. I’ll try to annotate it with comments prefixed with ###.

### The ed script exists and is on my PATH.
$ which ed
/Users/echosa/bin/ed

### This is the script. Pretty simple.
$ cat /Users/echosa/bin/ed
#!/bin/sh
ged -v -p* $@|lolcat

### ged is GNU ed installed with Homebrew and is found.
$ which ged
/usr/local/bin/ged

### lolcat is a ruby gem which is installed and found on the PATH.
$ which lolcat
/Users/echosa/.rvm/gems/ruby-2.2.0/bin/lolcat

### Just proving that ged works.
$ ged
#ged works
q

### And proving that lolcat works.
$ lolcat
lolcat works
lolcat works
^C$

### Finally, proving that my ed script works
$ ed
*#my ed script works
*q

### $EDITOR is set to my ed script
$ echo $EDITOR
ed

### $HOMEBREW_EDITOR is not set, so it defaults to $EDITOR
$ echo $HOMEBREW_EDITOR

### So, let's try to brew edit a formula
$ brew edit git
Editing /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/git.rb
/Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'lolcat' (>= 0) among 14 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/echosa/.gem/ruby/2.2.0:/Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0', execute `gem env` for more information
	from /Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
	from /Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
	from /Users/echosa/.rvm/gems/ruby-2.2.0/bin/lolcat:22:in `<main>'
	from /Users/echosa/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:24:in `eval'
	from /Users/echosa/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:24:in `<main>'
q

### That errors out! Seems like lolcat can't be found. Interesting. Perhaps it's an env issue while inside brew edit. Let's check by using plain `ged` for now.
$ EDITOR=ged brew edit git
Editing /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/git.rb
6376

### Perfect. No error. We're now inside the editor, so let's use `!` to run shell commands to inspect the environment. We'll start by looking for `lolcat`.
!which lolcat
/Users/echosa/.rvm/gems/ruby-2.2.0/bin/lolcat
!

### Huh. So, while in `brew edit`, lolcat can be found. That's good. Let's try to run it.
!lolcat
/Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'lolcat' (>= 0) among 14 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/echosa/.gem/ruby/2.2.0:/Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/gems/2.2.0', execute `gem env` for more information
	from /Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/dependency.rb:324:in `to_spec'
	from /Users/echosa/.rvm/rubies/ruby-2.2.0/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_gem.rb:64:in `gem'
	from /Users/echosa/.rvm/gems/ruby-2.2.0/bin/lolcat:22:in `<main>'
	from /Users/echosa/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:24:in `eval'
	from /Users/echosa/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:24:in `<main>'
!

### And there's the error, reproduced. We can quit the editor now.
q
$

(Sean Molenaar) #2

Yeah, it’s probably due to the filtering brew does when executing it’s commands. I don’t think I can help you much though, the rvm based setup with a custom editor makes it very far outside anything I’ve ever used brew for.