Created
April 6, 2011 14:22
-
-
Save mattpolito/905731 to your computer and use it in GitHub Desktop.
big pimpin' irbrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Color definitions | |
ANSI = {} | |
ANSI[:RESET] = "\e[0m" | |
ANSI[:BOLD] = "\e[1m" | |
ANSI[:UNDERLINE] = "\e[4m" | |
ANSI[:LGRAY] = "\e[0;37m" | |
ANSI[:GRAY] = "\e[1;30m" | |
ANSI[:RED] = "\e[31m" | |
ANSI[:GREEN] = "\e[32m" | |
ANSI[:YELLOW] = "\e[33m" | |
ANSI[:BLUE] = "\e[34m" | |
ANSI[:MAGENTA] = "\e[35m" | |
ANSI[:CYAN] = "\e[36m" | |
ANSI[:WHITE] = "\e[37m" | |
# IRB Options | |
IRB.conf[:AUTO_INDENT] = true | |
IRB.conf[:SAVE_HISTORY] = 1000 | |
IRB.conf[:EVAL_HISTORY] = 200 | |
IRB.conf[:PROMPT][:SIMPLE_COLOR] = { | |
:PROMPT_I => "#{ANSI[:CYAN]}>>#{ANSI[:RESET]} ", | |
:PROMPT_N => "#{ANSI[:CYAN]}>>#{ANSI[:RESET]} ", | |
:PROMPT_C => "#{ANSI[:RED]}>>#{ANSI[:RESET]} ", | |
:PROMPT_S => "#{ANSI[:YELLOW]}>>#{ANSI[:RESET]} ", | |
:RETURN => "#{ANSI[:GREEN]}>>#{ANSI[:RESET]} %s\n", | |
:AUTO_INDENT => true } | |
IRB.conf[:PROMPT_MODE] = :SIMPLE_COLOR | |
def extend_console(name, care = true, required = true) | |
if care | |
require name if required | |
yield if block_given? | |
$console_extensions << "#{ANSI[:GREEN]}#{name}#{ANSI[:RESET]}" | |
else | |
$console_extensions << "#{ANSI[:GRAY]}#{name}#{ANSI[:RESET]}" | |
end | |
rescue LoadError | |
$console_extensions << "#{ANSI[:RED]}#{name}#{ANSI[:RESET]}" | |
end | |
$console_extensions = [] | |
# Wirble | |
extend_console 'wirble' do | |
Wirble.init(:history_uniq => false) | |
Wirble.colorize | |
end | |
# Awesome Print | |
extend_console 'ap' | |
# Factory Girl | |
extend_console 'factory_girl' do | |
def enable_factories | |
paths = ['test/factories', 'spec/factories'] | |
Factory.definition_file_paths = paths.inject([]) { |s,i| s << Rails.root.join(i) } | |
Factory.find_definitions | |
end | |
end | |
extend_console 'rails3', defined?(ActiveSupport::Notifications), false do | |
$odd_or_even_queries = false | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args| | |
$odd_or_even_queries = !$odd_or_even_queries | |
color = $odd_or_even_queries ? ANSI[:CYAN] : ANSI[:MAGENTA] | |
event = ActiveSupport::Notifications::Event.new(*args) | |
time = "%.1fms" % event.duration | |
name = event.payload[:name] | |
sql = event.payload[:sql].gsub("\n", " ").squeeze(" ") | |
puts " #{ANSI[:UNDERLINE]}#{color}#{name} (#{time})#{ANSI[:RESET]} #{sql}" | |
end | |
end | |
# Rails 2 | |
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER') | |
require 'logger' | |
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT) | |
elsif defined?(Rails) # Rails 3 | |
#require 'logger' | |
#Rails.logger = Logger.new(STDOUT) | |
#ActiveRecord::Base.logger = Rails.logger | |
end | |
# Easily print methods local to an object's class | |
class Object | |
def local_methods | |
(methods - Object.instance_methods).sort | |
end | |
end | |
# copy a string to clipboard | |
def pbcopy(string) | |
`echo "#{string}" | pbcopy` | |
string | |
end | |
puts "#{ANSI[:GRAY]}~> Console extensions:#{ANSI[:RESET]}\n -- #{$console_extensions.join("\n -- ")}#{ANSI[:RESET]}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cobbled together from different sources. the extend_console idea comes from patmcnally (who says he can't take credit for it, but great idea none the less)