Skip to content

Instantly share code, notes, and snippets.

@iwillspeak
Last active December 20, 2015 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwillspeak/6095329 to your computer and use it in GitHub Desktop.
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
#! /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