Created
January 20, 2015 18:59
-
-
Save bkemper/431a74c123debc3bb928 to your computer and use it in GitHub Desktop.
Rake task with editor input
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
task :with_editor do | |
require "tempfile" | |
temp_file = Tempfile.new("notes") | |
unless editor = ENV["EDITOR"] | |
abort "Please define your editor." | |
end | |
# Open editor | |
system("#{editor} #{temp_file.path}") | |
# | |
# Do something with file here | |
# | |
# Delete temp file | |
temp_file.unlink | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks cool! definitely give it a try -- fyi you can avoid
unlink
by passing a block toTempfile#new