Sha256: 897fa058c6a3a70478cc9a9da60bc61620dcb9fa89524413ae83921c9787c02f

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ro_commands-0.0.3 lib/ro_commands/helpers/bash.rb
ro_commands-0.0.2 lib/ro_commands/helpers/bash.rb