Sha256: e652a9dcacb6338089f3e38af2f7a0aafb0888c887f4abc877b14a8dfb070206

Contents?: true

Size: 889 Bytes

Versions: 9

Compression:

Stored size: 889 Bytes

Contents

class Thor
  module Actions
    # launch configured editor to retreive message/string
    # see http://osdir.com/ml/ruby-talk/2010-06/msg01424.html
    # see https://gist.github.com/rkumar/456809
    # see http://rdoc.info/github/visionmedia/commander/master/Commander/UI.ask_editor
    def ask_editor(initial_text = '', editor: nil, footer: nil)
      editor ||= ENV['EDITOR'] || 'vi'
      initial_text += "\n\n#{footer}" if footer
      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(footer, '') if footer
      text.chomp.strip
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gitx-2.23.0.ci.162.1 lib/gitx/extensions/thor.rb
gitx-2.23.0 lib/gitx/extensions/thor.rb
gitx-2.22.0.ci.154.1 lib/gitx/extensions/thor.rb
gitx-2.22.0 lib/gitx/extensions/thor.rb
gitx-2.21.5.ci.153.1 lib/gitx/extensions/thor.rb
gitx-2.21.5.ci.151.1 lib/gitx/extensions/thor.rb
gitx-2.21.5 lib/gitx/extensions/thor.rb
gitx-2.21.4.ci.145.1 lib/gitx/extensions/thor.rb
gitx-2.21.4 lib/gitx/extensions/thor.rb