require_relative "out" require "open3" module Bash class << self def status @@status ||= nil end def out @@out ||= nil end def err @@err ||= nil end end def _bash(cmd) cmd = handle_path(cmd) Out.out("Running: #{cmd}") @@out, @@err, @@status = Open3.capture3(cmd) Out.out @@out Out.out @@err @@status end # bash capture cmds result def bashc(*cmds) bash(*cmds) if @@status.success? @@out else @@err end end def handle_path(cmd) path = %r{\w*/(\w|/|-)+} r = cmd.gsub(path) do |m| "\'#{m}\'" end end def bash(*cmds) unless cmds.empty? _bash(cmds.flatten.join(" && ")) end end def bash_per(*cmds) cmds.each do |c| bash c end end def bash_lines(cmd) bash(cmd).split("\n") end end