Browse files

better editor handling for blog:new; fixes #65

  • Loading branch information...
1 parent c02557a commit 7eef28ffa023fcfd09b758a3d054d626c7fa4c8b @zzak zzak committed Oct 19, 2012
Showing with 12 additions and 1 deletion.
  1. +12 −1 Thorfile
View
13 Thorfile
@@ -1,4 +1,5 @@
require "fileutils"
+require "shellwords"
class Blog < Thor
TEMPLATE = (<<-TEXT).gsub(/^ +/, '')
@@ -21,7 +22,17 @@ class Blog < Thor
date = Time.now.strftime('%Y-%m-%d')
file = "_posts/#{date}-#{title.downcase.gsub(/[!.,;:+=-]/, '').gsub(/\W+/, '-')}.markdown"
File.open(file, 'wb') { |f| f.write(post) }
- system "$EDITOR #{file}"
+ editor = ENV['VISUAL'] || ENV['EDITOR']
+ if !editor
+ abort("Either set $VISUAL or $EDITOR")
+ else
+ commands = Shellwords.shellwords(editor)
+ commands << file
+ success = system(*commands)
+ if !success
+ abort("Could not run '#{editor} #{file}', exit code: #{$?.exitstatus}")
+ end
+ end
end
end

0 comments on commit 7eef28f

Please sign in to comment.