Top Level Namespace
Defined Under Namespace
Classes: Environment
Class Method Summary collapse
-
.method_missing(m, *args, &block) ⇒ Object
still could absolutely be more cleaned up, but it works.
Instance Method Summary collapse
- #as_background(&block) ⇒ Object
-
#capture(*cmd, &block) ⇒ Object
This explicitly doesn’t support pipelining, as the output is ripped out of sequence.
-
#cd(dir = nil) ⇒ Object
note for later documentation: any aliases of cd must be functions, not environmental aliases.
- #in_pipeline(async: true, &block) ⇒ Object
- #popd ⇒ Object
- #pushd(dir = nil) ⇒ Object
- #run(file, *args) ⇒ Object
-
#sourcesh(file) ⇒ Object
Defines
bashpsuedo-compatibility. - #which(command) ⇒ Object
- #with_all_out_as(file) ⇒ Object
- #with_stderr_as(file = STDERR) ⇒ Object
- #with_stderr_as_stdout ⇒ Object
- #with_stdin_as(file = STDIN) ⇒ Object
-
#with_stdout_as(file = STDOUT) ⇒ Object
If you want to append, you need to get the file object yourself.
- #with_stdout_as_stderr ⇒ Object
Class Method Details
.method_missing(m, *args, &block) ⇒ Object
still could absolutely be more cleaned up, but it works
208 209 210 211 212 213 214 215 |
# File 'lib/rash.rb', line 208 def self.method_missing(m, *args, &block) exe = which(m.to_s) if exe || ($env.alias?(m) && !$env.aliasing_disabled) $env.dispatch(m, *args) else super end end |
Instance Method Details
#as_background(&block) ⇒ Object
17 18 19 |
# File 'lib/rash/jobcontrol.rb', line 17 def as_background(&block) $env.async(&block) end |
#capture(*cmd, &block) ⇒ Object
This explicitly doesn’t support pipelining, as the output is ripped out of sequence.
37 38 39 40 41 42 43 44 45 |
# File 'lib/rash/capturing.rb', line 37 def capture(*cmd, &block) if block_given? $env.capture_block(&block) elsif cmd.size > 0 && (which(cmd[0]) || ($env.alias?(m) && !$env.aliasing_disabled)) $env.capture_command(cmd[0].to_s, *cmd[1..]) else raise ArgumentError.new("nothing to capture from") end end |
#cd(dir = nil) ⇒ Object
note for later documentation: any aliases of cd must be functions, not environmental aliases. Limitation of implementation.
136 137 138 139 140 141 142 143 |
# File 'lib/rash.rb', line 136 def cd(dir = nil) d = dir case d when File, Dir d = d.path if File.directory?(d.path) end $env.chdir(d) end |
#in_pipeline(async: true, &block) ⇒ Object
192 193 194 195 196 197 198 |
# File 'lib/rash/pipeline.rb', line 192 def in_pipeline(async: true, &block) if async $env.make_pipeline(&block) else $env.make_sync_pipeline(&block) end end |
#popd ⇒ Object
153 154 155 |
# File 'lib/rash.rb', line 153 def popd $env.pop_dir end |
#pushd(dir = nil) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/rash.rb', line 145 def pushd(dir = nil) case dir when File, Dir dir = dir.path if File.directory(dir.path) end $env.push_dir(dir) end |
#run(file, *args) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/rash.rb', line 157 def run(file, *args) filename = file.to_s exe = (filename.start_with?("/") ? filename : File.(filename.strip)) unless File.executable?(exe) raise SystemCallError.new("No such executable file - #{exe}", Errno::ENOENT::Errno) end $env.dispatch(exe, *args, literal: true) end |
#sourcesh(file) ⇒ Object
Defines bash psuedo-compatibility. Filesystem effects happen like normal and environmental variable changes are copied
This is an artifact of an old design and is deprecated until further notice.
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/rash.rb', line 172 def sourcesh(file) bash_env = lambda do |cmd = nil| tmpenv = `#{cmd + ';' if cmd} printenv` tmpenv.split("\n").grep(/[a-zA-Z0-9_]+=.*/).map {|l| l.split("=")} end bash_source = lambda do |f| Hash[bash_env.call("source #{File.realpath f}") - bash_env.()] end bash_source.call(file).each {|k,v| ENV[k] = v if k != "SHLVL" && k != "_"} end |
#which(command) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/rash.rb', line 185 def which(command) cmd = File.(command.to_s) return cmd if File.executable?(cmd) && !File.directory?(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |pt| path = File.(pt) exts.each do |ext| exe = File.join(path, "#{command}#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end nil end |
#with_all_out_as(file) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rash/redirection.rb', line 142 def with_all_out_as(file) $env.stdout = file $env.stderr = $stdout if block_given? begin yield $stdout ensure $env.reset_stdout $env.reset_stderr end end end |
#with_stderr_as(file = STDERR) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rash/redirection.rb', line 98 def with_stderr_as(file = STDERR) $env.stderr = file if block_given? begin yield $stderr ensure $env.reset_stderr end end end |
#with_stderr_as_stdout ⇒ Object
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rash/redirection.rb', line 131 def with_stderr_as_stdout $env.stderr = $stdout if block_given? begin yield $stderr ensure $env.reset_stderr end end end |
#with_stdin_as(file = STDIN) ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rash/redirection.rb', line 109 def with_stdin_as(file = STDIN) $env.stdin = file if block_given? begin yield $stdin ensure $env.reset_stdin end end end |
#with_stdout_as(file = STDOUT) ⇒ Object
If you want to append, you need to get the file object yourself. Check if not flushing immediately is a concern. If so, set $stdout.sync for files
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rash/redirection.rb', line 87 def with_stdout_as(file = STDOUT) $env.stdout = file if block_given? begin yield $stdout ensure $env.reset_stdout end end end |
#with_stdout_as_stderr ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/rash/redirection.rb', line 120 def with_stdout_as_stderr $env.stdout = $stderr if block_given? begin yield $stdout ensure $env.reset_stdout end end end |