Skip to content

Instantly share code, notes, and snippets.

@tobstarr
Created May 24, 2011 09:56
Show Gist options
  • Save tobstarr/988450 to your computer and use it in GitHub Desktop.
Save tobstarr/988450 to your computer and use it in GitHub Desktop.
def find_cmd(*commands)
dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR)
commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
full_path_command = nil
found = commands.detect do |cmd|
dir = dirs_on_path.detect do |path|
full_path_command = File.join(path, cmd)
File.executable? full_path_command
end
end
found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment