lib/ro_commands/helpers/bash.rb in ro_commands-0.0.1 vs lib/ro_commands/helpers/bash.rb in ro_commands-0.0.2

- old
+ new

@@ -1,18 +1,44 @@ 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) - result = `#{cmd}` - Out.out result + Out.out("Running: #{cmd}") + @@out, @@err, @@status = Open3.capture3(cmd) + Out.out @@out + Out.out @@err + @@status end - def handle_path(cmd) - r = cmd[/\/(\w|\/)*/] - if r - cmd.gsub! r, "\'#{r}\'" + # bash capture cmds result + def bashc(*cmds) + bash(*cmds) + if @@status.success? + @@out else - cmd + @@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?