Module: Thor::Actions
- Included in:
- Gitx::Cli::BaseCommand
- Defined in:
- lib/gitx/extensions/thor.rb
Instance Method Summary collapse
-
#ask_editor(initial_text = '', editor: nil, footer: nil) ⇒ Object
launch configured editor to retreive message/string see osdir.com/ml/ruby-talk/2010-06/msg01424.html see gist.github.com/rkumar/456809 see rdoc.info/github/visionmedia/commander/master/Commander/UI.ask_editor.
Instance Method Details
#ask_editor(initial_text = '', editor: nil, footer: nil) ⇒ Object
launch configured editor to retreive message/string see osdir.com/ml/ruby-talk/2010-06/msg01424.html see gist.github.com/rkumar/456809 see rdoc.info/github/visionmedia/commander/master/Commander/UI.ask_editor
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitx/extensions/thor.rb', line 9 def ask_editor(initial_text = '', editor: nil, footer: nil) editor ||= ENV['EDITOR'] || 'vi' initial_text += "\n\n#{}" if text = ::Tempfile.open('text.md') do |f| f << initial_text f.flush flags = case editor when 'mate', 'emacs', 'subl' '-w' when 'mvim' '-f' else '' end pid = fork { exec([editor, flags, f.path].join(' ')) } Process.waitpid(pid) File.read(f.path) end text = text.gsub(, '') if text.chomp.strip end |