Skip to content

Instantly share code, notes, and snippets.

@sahib
Created December 9, 2011 13:45
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 sahib/1451589 to your computer and use it in GitHub Desktop.
Save sahib/1451589 to your computer and use it in GitHub Desktop.
require 'find'
require 'tempfile'
$license = <<-eos
/* Cats insert there license here
* Hmm. Replace this.
*/
eos
# Insert license at beginning, using a crappy tmp file.
def do_prepend path
Tempfile.open File.basename(path) do |tempfile|
tempfile << $license
File.open(path, 'r+') do |file|
tempfile << file.read
file.pos = tempfile.pos = 0
file << tempfile.read
end
end
end
# Recurse everything in $pwd
Find.find('./') do |file|
if file.end_with? ".cc" or file.end_with? ".hh"
if File.writable? file
puts "Adding license to: #{file}"
do_prepend file
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment