Skip to content

Open gem command #804

Merged
merged 14 commits into from Feb 5, 2014

3 participants

@quozd
quozd commented Feb 1, 2014

Opens gem source code in EDITOR. See #789 for details.

Usage:

Open in default editor:

gem open gem_name

Open using vim:

gem open gem_name -e vim
@quozd quozd referenced this pull request Feb 1, 2014
Closed

Open gem source in editor #789

@quozd
quozd commented Feb 1, 2014

hm, looks like spawn function is not present in ruby 1.8.7, fork AFAIK is not cross-platform. Any ideas?

@quozd quozd closed this Feb 1, 2014
@quozd quozd reopened this Feb 1, 2014
@drbrain drbrain commented on the diff Feb 3, 2014
lib/rubygems/commands/open_command.rb
+ end
+
+ def description # :nodoc:
+ <<-EOF
+ The open command opens gem in editor and changes current path
+ to gem's source directory. Editor can be specified, otherwise
+ $EDITOR would be invoked.
+ EOF
+ end
+
+ def usage # :nodoc:
+ "#{program_name} GEMNAME [-e EDITOR]"
+ end
+
+ def get_env_editor
+ ENV['GEM_EDITOR'] ||
@drbrain
RubyGems member
drbrain added a note Feb 3, 2014

Can you include a description of all the environment variables that the open command will use in the description? Only $EDITOR is mentioned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drbrain drbrain commented on an outdated diff Feb 3, 2014
lib/rubygems/commands/open_command.rb
+
+ found = open_gem(get_one_gem_name)
+
+ terminate_interaction 1 unless found
+ end
+
+ def open_gem name
+ spec = spec_for name
+ return false unless spec
+
+ open_editor(spec.full_gem_path)
+ end
+
+ def open_editor path
+ Dir.chdir(path) do
+ pid = spawn(@editor, path)
@drbrain
RubyGems member
drbrain added a note Feb 3, 2014

spawn is in ruby 1.9 and newer but RubyGems still supports ruby 1.8.7. Can you switch this to use fork + exec instead here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drbrain drbrain commented on an outdated diff Feb 3, 2014
lib/rubygems/commands/open_command.rb
+ terminate_interaction 1 unless found
+ end
+
+ def open_gem name
+ spec = spec_for name
+ return false unless spec
+
+ open_editor(spec.full_gem_path)
+ end
+
+ def open_editor path
+ Dir.chdir(path) do
+ pid = spawn(@editor, path)
+ Process.detach(pid)
+ end
+ #unless Gem::Util.silent_system(@editor, path)
@drbrain
RubyGems member
drbrain added a note Feb 3, 2014

Please remove this commented-out code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@drbrain
RubyGems member
drbrain commented Feb 3, 2014

Are there any features from gem-open or gem-edit that are missing here? I don't see any shared code with the existing implementations.

/c @tpope @fnando

@tpope
tpope commented Feb 3, 2014

As I read it, this won't work if the editor option or variable contains an argument, for example gvim -f. The best solution I know of is to split on /\s+/.

Other than that, looks great.

@quozd
quozd commented Feb 4, 2014

looks like I have some issues with ruby 1.8, will take a look and fix in the evening. Don't have proper environment right now.

Other remarks were fixed

@quozd
quozd commented Feb 4, 2014

Guys, I fixed all issues related to my code, but some tests are failing with ruby 1.8.7. I have no idea how my code could influence to this tests. Could somebody take a look and show me where the issue is?
cast @drbrain

@drbrain
RubyGems member
drbrain commented Feb 4, 2014

Those tests are also failing on master so you're good to go!

I'll fix those failing tests and merge your pull request shortly.

@drbrain drbrain merged commit d92087e into rubygems:master Feb 5, 2014

1 check failed

Details default The Travis CI build failed
@drbrain drbrain added a commit that referenced this pull request Feb 5, 2014
@drbrain drbrain Add #789, #804 to History
Fixes #789
bd27286
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.