Commit 2c0f2386 authored by Samuel Giddins's avatar Samuel Giddins

[Spec::Edit] Use Executable.which

parent e547edd6
...@@ -48,32 +48,23 @@ module Pod ...@@ -48,32 +48,23 @@ 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',
# 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