Sha256: 647755daaf0bbbe9436e3fbade9565dafc07c7f11ed721951cc43b6158a1862f
Contents?: true
Size: 1.1 KB
Versions: 21
Compression:
Stored size: 1.1 KB
Contents
require 'English' class Thor module Actions # execute a shell command and raise an error if non-zero exit code is returned # return the string output from the command def run_cmd(cmd, options = {}) say "$ #{cmd}" output = `#{cmd}` success = $CHILD_STATUS.to_i == 0 fail "#{cmd} failed" unless success || options[:allow_failure] output end # launch configured editor to retreive message/string # see http://osdir.com/ml/ruby-talk/2010-06/msg01424.html # see https://gist.github.com/rkumar/456809 # see http://rdoc.info/github/visionmedia/commander/master/Commander/UI.ask_editor def ask_editor(initial_text = '', editor = nil) editor ||= ENV['EDITOR'] || 'vi' Tempfile.open('reviewrequest.md') do |f| f << initial_text f.flush flags = case editor when 'mate', 'emacs', 'subl' '-w' when 'mvim' '-f' else '' end pid = fork { exec([editor, flags, f.path].join(' ')) } Process.waitpid(pid) File.read(f.path) end end end end
Version data entries
21 entries across 21 versions & 1 rubygems