Przeglądaj źródła

Only write the history back if it changed.

Lucas Stadler 14 lat temu
rodzic
commit
f7df8cb876
1 zmienionych plików z 7 dodań i 5 usunięć
  1. 7 5
      .irbrc

+ 7 - 5
.irbrc

13
    @history = hist_file
13
    @history = hist_file
14
    @src     = hist_src
14
    @src     = hist_src
15
    
15
    
16
    last_history = File.read @history rescue ""
17
    last_history.lines.each do |line|
18
      @src.push line.strip
16
    @last_history = File.read(@history).lines.map &:strip rescue []
17
    @last_history.each do |line|
18
      @src.push line
19
    end
19
    end
20
    
20
    
21
    at_exit do
21
    at_exit do
22
      puts "Writing history back to #{@history}"
23
      File.write @history, @src.to_a.uniq.reduce { |x,y| "#{x}\n#{y}" }
22
      unless @last_history == @src.to_a.uniq
23
        puts "Writing changed history back to #{@history}"
24
        File.write @history, @src.to_a.uniq.reduce { |x,y| "#{x}\n#{y}" }
25
      end
24
    end
26
    end
25
  end
27
  end
26
end
28
end