Created
August 29, 2011 00:41
-
-
Save noahhl/1177468 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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