<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Enrique Delgado Monroy: Interactive Ruby Console Tip: Remember the last X commands</title>
    <link>http://www.enriquedelgado.com/articles/2007/04/25/interactive-ruby-console-tip-remember-the-last-x-commands-even-after-logging-out</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Work, Life, Stuff</description>
    <item>
      <title>Interactive Ruby Console Tip: Remember the last X commands</title>
      <description>&lt;p&gt;This is an excellent tip by &lt;a href="http://www.clarkware.com"&gt;Mike Clark&lt;/a&gt; to make &lt;span class="caps"&gt;IRB&lt;/span&gt; remember the last X number of commands even after you exit and restart &lt;span class="caps"&gt;IRB&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;This is great when developing and after modifying a model, you don&amp;#8217;t have to re-type everyting once again :)&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;&amp;#8220;Simply add the code below to your ~/.irbrc file. Then you can use up-arrow to cycle through the history, even
after restarting &lt;span class="caps"&gt;IRB&lt;/span&gt;. It relies on the built-in history of readline, so you&amp;#8217;ll need readline installed. The code below also enables completion using the &lt;span class="caps"&gt;TAB&lt;/span&gt; key&amp;#8221;&lt;/p&gt;
	&lt;/blockquote&gt;


&lt;pre style="overflow: auto; background: #EEE;"&gt;
IRB.conf[:PROMPT_MODE] = :SIMPLE

require 'irb/completion'

IRB.conf[:AUTO_INDENT] = true

# Session History

HISTFILE = "~/.irb.hist" unless defined? HISTFILE
MAXHISTSIZE = 100 unless defined? MAXHISTSIZE

begin
if defined? Readline::HISTORY
histfile = File::expand_path(HISTFILE)
if File::exists?(histfile)
lines = IO::readlines(histfile).collect { |line| line.chomp }
Readline::HISTORY.push(*lines)
end

Kernel::at_exit {
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
lines = lines[-MAXHISTSIZE, MAXHISTSIZE] if lines.nitems &amp;gt;
MAXHISTSIZE
File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) {|f|
lines.each {|line| f.puts line }
}
}
end
end
&lt;/pre&gt;</description>
      <pubDate>Wed, 25 Apr 2007 10:47:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9bc46352-8e4c-4521-9bc8-ae23b7ec3896</guid>
      <author>Enrique Delgado</author>
      <link>http://www.enriquedelgado.com/articles/2007/04/25/interactive-ruby-console-tip-remember-the-last-x-commands-even-after-logging-out</link>
      <category>Rails</category>
      <category>ruby</category>
      <category>irb</category>
      <category>tips</category>
    </item>
  </channel>
</rss>
