irbrc.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # This is the common irbrc file used by all rvm ruby installations.
  2. # This file will be overriden every time you update rvm.
  3. # Calculate the ruby string.
  4. rvm_ruby_string = ENV["rvm_ruby_string"] ||
  5. (
  6. ENV['GEM_HOME'] &&
  7. ( path = ( File.realpath(ENV['GEM_HOME'].to_s) rescue nil ) ) &&
  8. ( path = $1 if path =~ /(.+)\/$/ ; true ) &&
  9. String(String(path).split(/\//).last).split(/@/).first
  10. ) ||
  11. ("#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" rescue nil) ||
  12. (RUBY_DESCRIPTION.split(" ")[1].sub('p', '-p') rescue nil ) ||
  13. (`ruby -v` || '').split(" ")[1].sub('p', '-p')
  14. # cut ruby- ... everyone knows it's ruby
  15. rvm_ruby_string = $1 if rvm_ruby_string =~ /^ruby[- ](.*)/
  16. # Set up the prompt to be RVM specific.
  17. @prompt = {
  18. :PROMPT_I => "#{rvm_ruby_string} :%03n > ", # default prompt
  19. :PROMPT_S => "#{rvm_ruby_string} :%03n%l> ", # known continuation
  20. :PROMPT_C => "#{rvm_ruby_string} :%03n > ",
  21. :PROMPT_N => "#{rvm_ruby_string} :%03n?> ", # unknown continuation
  22. :RETURN => " => %s \n",
  23. :AUTO_INDENT => true
  24. }
  25. IRB.conf[:PROMPT] ||= {}
  26. IRB.conf[:PROMPT][:RVM] = @prompt
  27. IRB.conf[:PROMPT_MODE] = :RVM if IRB.conf[:PROMPT_MODE] == :DEFAULT
  28. require "irb/completion" rescue nil
  29. IRB.conf[:SAVE_HISTORY] = 100
  30. IRB.conf[:HISTORY_FILE] = File.join(ENV["HOME"], ".irb-history")
  31. # Load the user's irbrc file, if possible.
  32. # Report any errors that occur.
  33. begin
  34. load File.join(ENV["HOME"], ".irbrc") if File.exist?("#{ENV["HOME"]}/.irbrc")
  35. rescue LoadError => load_error
  36. puts load_error
  37. rescue => exception
  38. puts "Error : 'load #{ENV["HOME"]}/.irbrc' : #{exception.message}"
  39. end