module Exedit
A ruby external editor interface
Exedit
main module
Constants
- VERSION
Attributes
editor[RW]
Public Class Methods
available_editors()
click to toggle source
All editors available on the current system
# File lib/exedit/exedit.rb, line 23 def available_editors if !defined? @options base_editors.select { |_editor, command| Command.which(command.split(' ')[0]) } else options.editors.select { |_editor, command| Command.which(command.split(' ')[0]) } end end
edit(content, editor: nil, command: nil)
click to toggle source
Edits the given content in a tempfile
# File lib/exedit/exedit.rb, line 18 def edit(content, editor: nil, command: nil) Editor.new(edit_command(editor, command), content: content).open end
open(file = nil, editor: nil, command: nil)
click to toggle source
Opens a file (defaults to a tempfile which will be deleted) for editing in the external editor
# File lib/exedit/exedit.rb, line 13 def open(file = nil, editor: nil, command: nil) Editor.new(edit_command(editor, command), file).open end
Private Class Methods
base_editors()
click to toggle source
# File lib/exedit/exedit.rb, line 41 def base_editors { vi: 'vi', vim: 'vim', nano: 'nano', pico: 'pico', sublime: 'subl -w -n', textmate: 'mate -w' } end
default_editor()
click to toggle source
# File lib/exedit/exedit.rb, line 37 def default_editor options.default_editor || available_editors.keys.first end
default_options()
click to toggle source
# File lib/exedit/exedit.rb, line 52 def default_options { editors: base_editors.select { |key, _value| available_editors.include? key } } end
edit_command(editor, command)
click to toggle source
# File lib/exedit/exedit.rb, line 33 def edit_command(editor, command) command || options.editors[editor || default_editor] end