Selaa lähdekoodia

Only write the history back if it changed.

Lucas Stadler 14 vuotta sitten
vanhempi
commit
f7df8cb876
1 muutettua tiedostoa jossa 7 lisäystä ja 5 poistoa
  1. 7 5
      .irbrc

+ 7 - 5
.irbrc

@ -13,14 +13,16 @@ class StoredHistory
13 13
    @history = hist_file
14 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 19
    end
20 20
    
21 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 26
    end
25 27
  end
26 28
end