Skip to content

Instantly share code, notes, and snippets.

@eagereyes
Forked from AlanQuatermain/gist:98622
Created April 20, 2009 23:00
Show Gist options
  • Save eagereyes/98826 to your computer and use it in GitHub Desktop.
Save eagereyes/98826 to your computer and use it in GitHub Desktop.
Finds the project name if file in subdir "Classes". Also tried to get file's creation time, but need some more Mac-specific Ruby-fu, it seems (creation time is not POSIX standard)
#!/usr/bin/ruby
require 'osx/cocoa'
require 'date'
OSX.require_framework "AddressBook"
filePath = "%%%{PBXFilePath}%%%"
fileName = File.basename(filePath)
projName = File.basename(File.dirname(filePath))
if projName == "Classes"
projName = File.basename(File.dirname(File.dirname(filePath)))
end
def file_uses_hash_comments(path)
fileExt = File.extname(path)
%w{.rb .pl .sh .csh .zsh}.each do |ext|
return true if fileExt == ext
end
false
end
me = OSX::ABAddressBook.sharedAddressBook.me
myName = "#{me.send(:valueForProperty, 'firstName')} #{me.send(:valueForProperty, 'lastName')}"
date = File.ctime(filePath)
headText = %{%%%{PBXHeadText}%%%}
c_mode = false
unless headText =~ /(^#!)|(\n# )/ or file_uses_hash_comments(filePath)
c_mode = true
end
puts "/*" if c_mode
%{#{fileName}
#{projName}
Created by #{myName} on #{date.mday}/#{date.month}/#{date.year}.
Copyright (c) #{date.year} #{myName}
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the project's author nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}.each_line do |line|
if c_mode
puts " * #{line}"
else
puts "# #{line}"
end
end
puts " *\n */" if c_mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment