class Rundoc::CodeCommand::Bash::Cd

special purpose class to persist cd behavior across the entire program we change the directory of the parent program (rundoc) rather than changing the directory of a spawned child (via exec, “, system, etc.)

Public Class Methods

new(line) click to toggle source
# File lib/rundoc/code_command/bash/cd.rb, line 7
def initialize(line)
  @line = line
end

Public Instance Methods

call(env) click to toggle source
# File lib/rundoc/code_command/bash/cd.rb, line 25
def call(env)
  line = @line.sub('cd', '').strip
  puts "running $ cd #{line}"

  supress_chdir_warning do
    Dir.chdir(line)
  end

  return nil
end
supress_chdir_warning() { || ... } click to toggle source

Ignore duplicate chdir warnings “warning: conflicting chdir during another chdir block”

# File lib/rundoc/code_command/bash/cd.rb, line 12
def supress_chdir_warning
  old_stderr     = $stderr
  capture_stderr = StringIO.new
  $stderr        = capture_stderr
  return yield
ensure
  if old_stderr
    $stderr = old_stderr
    capture_string = capture_stderr.string
    $stderr.puts capture_string if capture_string.each_line.count > 1 || !capture_string.include?("conflicting chdir")
  end
end