class GHI::Editor

Attributes

filename[R]

Public Class Methods

new(filename) click to toggle source
# File lib/ghi/editor.rb, line 6
def initialize filename
  @filename = filename
end

Public Instance Methods

gets(prefill) click to toggle source
# File lib/ghi/editor.rb, line 10
def gets prefill
  File.open path, 'a+' do |f|
    f << prefill if File.zero? path
    f.rewind
    system "#{editor} #{f.path}"
    return File.read(f.path).gsub(/(?:^#.*$\n?)+\s*\z/, '').strip
  end
end

Private Instance Methods

dir() click to toggle source
# File lib/ghi/editor.rb, line 38
def dir
  @dir ||= git_dir || Dir.tmpdir
end
editor() click to toggle source
# File lib/ghi/editor.rb, line 26
def editor
  editor   = GHI.config 'ghi.editor'
  editor ||= GHI.config 'core.editor'
  editor ||= ENV['VISUAL']
  editor ||= ENV['EDITOR']
  editor ||= 'vi'
end
git_dir() click to toggle source
# File lib/ghi/editor.rb, line 42
def git_dir
  return unless Commands::Command.detected_repo
  dir = `git rev-parse --git-dir 2>/dev/null`.chomp
  dir unless dir.empty?
end
path() click to toggle source
# File lib/ghi/editor.rb, line 34
def path
  File.join dir, filename
end