require 'irb/completion' require 'irb/ext/save-history' ARGV.concat [ "--readline", "--prompt-mode", "simple" ] IRB.conf[:PROMPT_MODE] = :SIMPLE # Save command history IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" # Custom pretty print certain obj types # # String: print length, content type and up to 128 bytes of inspect # Fixnum/BigNum: also print out the hex value module IRB class Irb def output_value if @context.inspect? case @context.last_value when Fixnum printf @context.return_format, "%s (0x%08x)"%[@context.last_value.inspect,@context.last_value] when Bignum printf @context.return_format, "%s (0x%016x)"%[@context.last_value.inspect,@context.last_value] when String lv = @context.last_value begin # yes, this spawns a shell command after every IRB eval. # fast enough for %99.99 of stuff f = IO.popen("file -","w+") f.write(lv) rescue ensure f.flush f.close_write fileout = f.read.gsub("/dev/stdin: ",'').chomp end ins = lv[0,128] if lv.length > 128 ins += "..." end printf @context.return_format, "length: %d\n=> content: %s\n=> value: %s\n"%[lv.length,fileout,ins.inspect] else printf @context.return_format, @context.last_value.inspect end else printf @context.return_format, @context.last_value end end end end