Last active
December 20, 2015 07:39
-
-
Save iwillspeak/6095329 to your computer and use it in GitHub Desktop.
Find a file in the current directory or in any of it's parents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'pathname' | |
def find_config_file(file_name, path) | |
path = Pathname(path) unless path.is_a? Pathname | |
path = path.realpath | |
path.ascend do |subpath| | |
location = subpath + file_name | |
return location if location.exist? | |
end | |
nil | |
end | |
ARGV.each do |filename| | |
puts find_config_file filename, '.' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment