Sha256: 9d13b1431c36f5a4dca7ecc4a256f16238adfccbdbce94b8d883b3b612f4895b

Contents?: true

Size: 573 Bytes

Versions: 8

Compression:

Stored size: 573 Bytes

Contents

require 'rib'
require 'tempfile'

module Rib::Edit
  extend Rib::Plugin
  Shell.use(self)

  module Imp
    def edit
      return if Rib::Edit.disabled?
      file = Tempfile.new(['rib.edit', '.rb'])
      file.puts(Rib.vars[:edit])
      file.close

      system("#{ENV['EDITOR']} #{file.path}")

      if (shell = Rib.shell).running?
        shell.send(:multiline_buffer).pop
      else
        shell.before_loop
      end

      shell.loop_eval(Rib.vars[:edit] = File.read(file.path))

    ensure
      file.close
      file.unlink
    end
  end

  Rib.extend(Imp)
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rib-1.2.0 lib/rib/more/edit.rb
rib-1.1.6 lib/rib/more/edit.rb
rib-1.1.5 lib/rib/more/edit.rb
rib-1.1.4 lib/rib/more/edit.rb
rib-1.1.3 lib/rib/more/edit.rb
rib-1.1.2 lib/rib/more/edit.rb
rib-1.1.1 lib/rib/more/edit.rb
rib-1.1.0 lib/rib/more/edit.rb