Sha256: 93e3901be05bf73d1108c6d3d69b61364d0b93b42a3274dad79e578a249425c2

Contents?: true

Size: 595 Bytes

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
t-4.0.0 lib/t/editor.rb