1

Background: I wrote a short script in MRI 1.9.2p320 for updating all my projects – http://git.io/eez8Kg . Tool which i utilize for the updating/pulling itself (git-up) is also able to automatically bundle project after it discover changed Gemfile. The problem is, that when i change directory in the Ruby script, it does not respect rvmrc/gemset of projects (each project has it's own gemset).

Question: How can i achieve to make cd in Ruby script behave same as in my terminal

I've tried:

  • replace Dir.chdir with cd command in the `s
  • replace Dir.chdir with cd command in the `s prepended with zsh -ci

Code:

Find.find('../..') do |f|
  if f =~ /\.git$/
    repository = f.gsub /\.git$/, ''
    Logger.new(STDOUT).info('Checking '){repository}
    Dir.chdir(repository){
      puts `git up`
    }
  end
end
4

1 に答える 1

0

Open3.html#popen3 FTW

zshin, zshout, zsherr = Open3.popen3('zsh') # Open new shell
zshin.puts 'cd ~/Projects/superimportant_project' # Change directory
zshin.puts 'rvm-prompt' # Verify rvmrc is respected
zshin.puts 'exit' # Exit the shell
while (line = zshout.gets)
  puts line
end

シェルを終了することは必須ではありませんが、たとえばrvm-prompt、他に何も起こさずにぶら下がったままになります。lsで同じことを試してみると、出口ラインは必要ありません。

于 2013-01-07T17:10:39.540 に答える