Class: TheFox::Timr::Helper::TerminalHelper
- Inherits:
-
Object
- Object
- TheFox::Timr::Helper::TerminalHelper
- Extended by:
- Error
- Defined in:
- lib/timr/helper/terminal_helper.rb
Overview
This class helps with Terminal operations.
Class Method Summary collapse
-
.external_editor_help(edit_text) ⇒ Object
Print help to external editor.
-
.run_external_editor(text = nil) ⇒ Object
Run external editor via EDITOR environment variable.
Class Method Details
.external_editor_help(edit_text) ⇒ Object
Print help to external editor.
45 46 47 48 49 50 |
# File 'lib/timr/helper/terminal_helper.rb', line 45 def external_editor_help(edit_text) edit_text << '# This is a comment.' edit_text << '# The first line should be a sentence. Sentence have dots at the end.' edit_text << '# The second line should be empty, if you provide a more detailed' edit_text << '# description from on the third line. Like on Git.' end |
.run_external_editor(text = nil) ⇒ Object
Run external editor via EDITOR environment variable.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/timr/helper/terminal_helper.rb', line 15 def run_external_editor(text = nil) case text when Array text = text.join("\n") end if !ENV['EDITOR'] || ENV['EDITOR'].length == 0 raise TerminalHelperError, 'EDITOR environment variable not set.' end tmpfile = Tempfile.new('timr_message') if text tmpfile.write(text) end tmpfile.close system_s = '%s %s' % [ENV['EDITOR'], tmpfile.path] system(system_s) tmpfile.open tmpfile_lines = tmpfile.read tmpfile.close tmpfile_lines .split("\n") .select{ |row| row[0] != '#' } .join("\n") end |