Sha256: 466169019a5f271323cd84a5d03c833d10bd332a7e3002c19b127f15787db285

Contents?: true

Size: 595 Bytes

Versions: 14

Compression:

Stored size: 595 Bytes

Contents

require 'tempfile'
require 'shellwords'

module T
  class Editor
    class << self
      def gets
        file = tempfile
        edit(file.path)
        File.read(file).strip
      ensure
        file.close
        file.unlink
      end

      def tempfile
        Tempfile.new('TWEET_EDITMSG')
      end

      def edit(path)
        system(Shellwords.join([editor, path]))
      end

      def editor
        ENV['VISUAL'] || ENV['EDITOR'] || system_editor
      end

      def system_editor
        RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'notepad' : 'vi'
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
t-3.1.0 lib/t/editor.rb
t-3.0.0 lib/t/editor.rb
t-2.10.0 lib/t/editor.rb
t-2.9.0 lib/t/editor.rb
t-2.8.0 lib/t/editor.rb
t-2.7.0 lib/t/editor.rb
t-2.6.0 lib/t/editor.rb
t-2.5.0 lib/t/editor.rb
t-2.4.0 lib/t/editor.rb
t-2.3.0 lib/t/editor.rb
t-2.2.1 lib/t/editor.rb
t-2.2.0 lib/t/editor.rb
t-2.1.0 lib/t/editor.rb
t-2.0.2 lib/t/editor.rb