Skip to content

Instantly share code, notes, and snippets.

@noahhl
Created August 29, 2011 00:41
Show Gist options
  • Select an option

  • Save noahhl/1177468 to your computer and use it in GitHub Desktop.

Select an option

Save noahhl/1177468 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Generate a shell of a script for the language you specify.
# Set up your script templates in ~/.scriptify
require 'optparse'
options = {:edit => false}
optparse = OptionParser.new do |opts|
opts.banner = "Usage: scriptify language filename"
opts.on("-s", "--edit", "Open in editor after creating") do |e|
options[:edit] = true
end
end
optparse.parse!
if ARGV.count != 2
puts optparse
Process.exit
end
language, filename = ARGV
unless File.exist? File.expand_path("~/.scriptify/#{language}")
puts "You don't seem to have a template defined in ~/.scriptify for this language."
Process.exit
end
`cp #{File.expand_path "~/.scriptify/#{language}"} #{filename}`
File.chmod(0755, filename)
puts "Initialized script at #{filename}"
if options[:edit]
exec "$EDITOR #{filename}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment