Sha256: 362f4f1e0447c97aa1fe6cb67fbe56cff96f489ccc3e1d812103a9e8aa8b674d

Contents?: true

Size: 597 Bytes

Versions: 2

Compression:

Stored size: 597 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

2 entries across 2 versions & 1 rubygems

Version Path
t-2.0.1 lib/t/editor.rb
t-2.0.0 lib/t/editor.rb