Skip to content

Commit

Permalink
Refs #24489 - Helper for editing text in editor (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbacovsky committed Nov 6, 2018
1 parent 5baac2d commit 049346d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/hammer_cli/utils.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'highline'
require 'tempfile'

class String
def format(params)
Expand Down Expand Up @@ -84,4 +85,15 @@ def self.capitalization
def self.interactive_output
@interactive_output ||= HighLine.new($stdin, IO.new(IO.sysopen('/dev/tty', 'w'), 'w'))
end

def self.open_in_editor(content, content_type: '', tempdir: '/tmp', suffix: '.tmp')
result = content
Tempfile.open([content_type, suffix], tempdir) do |f|
f.write(content)
f.rewind
system("#{ENV['EDITOR'] || 'vi'} #{f.path}")
result = f.read
end
result
end
end

0 comments on commit 049346d

Please sign in to comment.