Commit fde6f4aa authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #4600 from CocoaPods/seg-delete-redundant-which-method

[Spec::Edit] Use Executable.which
parents 776c18e3 b63c1f21
...@@ -48,32 +48,25 @@ module Pod ...@@ -48,32 +48,25 @@ module Pod
raise Informative, "#{filepath} doesn't exist." raise Informative, "#{filepath} doesn't exist."
end end
# Looks up an executable in the search paths
#
# @note
# Thank you homebrew
#
# @param [String] cmd
# the executable to look up
#
def which(cmd)
dir = ENV['PATH'].split(':').find { |p| File.executable? File.join(p, cmd) }
Pathname.new(File.join(dir, cmd)) unless dir.nil?
end
def which_editor def which_editor
editor = ENV['EDITOR'] editor = ENV['EDITOR']
# If an editor wasn't set, try to pick a sane default # If an editor wasn't set, try to pick a sane default
return editor unless editor.nil? return editor unless editor.nil?
editors = [
# Find Sublime Text 2 # Find Sublime Text 2
return 'subl' if which 'subl' 'subl',
# Find Textmate # Find Textmate
return 'mate' if which 'mate' 'mate',
# Find # BBEdit / TextWrangler # Find BBEdit / TextWrangler
return 'edit' if which 'edit' 'edit',
# Find Atom
'atom',
# Default to vim # Default to vim
return 'vim' if which 'vim' 'vim',
]
editor = editors.find { |e| Pod::Executable.which(e) }
return editor if editor
raise Informative, "Failed to open editor. Set your 'EDITOR' environment variable." raise Informative, "Failed to open editor. Set your 'EDITOR' environment variable."
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment