Module: Bash

Included in:
RoCommands::Base, RoHelpers::SetEnvsHelper::ClassMethods
Defined in:
lib/ro_helpers/bash.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.errObject



13
14
15
# File 'lib/ro_helpers/bash.rb', line 13

def err
  @@err ||= ''
end

.outObject



9
10
11
# File 'lib/ro_helpers/bash.rb', line 9

def out
  @@out ||= ''
end

.statusObject



5
6
7
# File 'lib/ro_helpers/bash.rb', line 5

def status
  @@status ||= ''
end

Instance Method Details

#_bash(cmd) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ro_helpers/bash.rb', line 30

def _bash(cmd)
  cmd = handle_path(cmd)
  Out.table("Running:", "#{cmd}")
  @@out, @@err, @@status = Open3.capture3(cmd)
  Out.out add_time(err)
  Out.out add_time(out)
  @@out
end

#add_time(str) ⇒ Object



39
40
41
42
43
# File 'lib/ro_helpers/bash.rb', line 39

def add_time(str)
  unless str.empty?
    "#{Time.now.strftime("%H:%M:%S")}: #{str}"
  end
end

#bash(*cmds) ⇒ Object



65
66
67
68
69
# File 'lib/ro_helpers/bash.rb', line 65

def bash(*cmds)
  unless cmds.empty?
    _bash(cmds.flatten.join(" && "))
  end
end

#bash_capture(*cmds) ⇒ Object Also known as: bashc

bash capture cmds result



46
47
48
# File 'lib/ro_helpers/bash.rb', line 46

def bash_capture(*cmds)
  bash(*cmds)
end

#bash_capture_array(*cmds) ⇒ Object Also known as: basha



52
53
54
# File 'lib/ro_helpers/bash.rb', line 52

def bash_capture_array(*cmds)
  bash_capture(*cmds).split("\n")
end

#bash_lines(cmd) ⇒ Object



97
98
99
# File 'lib/ro_helpers/bash.rb', line 97

def bash_lines(cmd)
  bash(cmd).split("\n")
end

#bash_per(*cmds) ⇒ Object



91
92
93
94
95
# File 'lib/ro_helpers/bash.rb', line 91

def bash_per(*cmds)
  cmds.each do |c|
    bash c
  end
end

#bash_system(*cmds) ⇒ Object Also known as: bashs, guard_bash



71
72
73
74
75
# File 'lib/ro_helpers/bash.rb', line 71

def bash_system(*cmds)
  unless cmds.empty?
    kernel_system(cmds.flatten.join(" && "))
  end
end

#bundle_exec(cmd) ⇒ Object Also known as: bx



85
86
87
# File 'lib/ro_helpers/bash.rb', line 85

def bundle_exec(cmd)
  kernel_system("bundle exec #{cmd}")
end

#errObject



26
27
28
# File 'lib/ro_helpers/bash.rb', line 26

def err
  @@err ||= ""
end

#handle_path(cmd) ⇒ Object



58
59
60
61
62
63
# File 'lib/ro_helpers/bash.rb', line 58

def handle_path(cmd)
  path = %r{\w*/(\w|/|-)+}
  r = cmd.gsub(path) do |m|
    "\'#{m}\'"
  end
end

#kernel_system(cmd) ⇒ Object



77
78
79
80
# File 'lib/ro_helpers/bash.rb', line 77

def kernel_system(cmd)
  Out.table "Running", "#{cmd}", "file:#{::File.basename __FILE__} line:#{__LINE__}"
  Kernel.system cmd
end

#outObject



22
23
24
# File 'lib/ro_helpers/bash.rb', line 22

def out
  @@out ||= ""
end

#statusObject



18
19
20
# File 'lib/ro_helpers/bash.rb', line 18

def status
  @@status ||= ""
end