Created
September 24, 2015 15:31
-
-
Save madwork/dc8eadd2ddc32569df71 to your computer and use it in GitHub Desktop.
Pry confie file
This file contains hidden or 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
require 'benchmark' | |
# sublime text as editor | |
Pry.config.editor = 'subl -w' | |
Pry.config.color = true | |
Pry.config.pager = true | |
# alias 'q' for 'exit' | |
Pry.config.commands.alias_command 'q', 'exit-all' | |
# Better colors - by default the headings for methods are too | |
# similar to method name colors leading to a "soup" | |
# These colors are optimized for use with Solarized scheme | |
# for your terminal | |
# Pry.config.ls.separator = "\n" # new lines between methods | |
Pry.config.ls.heading_color = :magenta | |
Pry.config.ls.public_method_color = :blue | |
Pry.config.ls.protected_method_color = :yellow | |
Pry.config.ls.private_method_color = :bright_black | |
# This prompt shows the ruby version (useful for RVM) | |
# Ex: [1.9.3] 0:(main) > | |
prompt_proc = lambda do |obj, nest_level, _| | |
ruby_info = "" | |
ruby_info << "\e[32m#{Rails.version}\e[0m@" if defined?(Rails) | |
ruby_info << "\e[31m#{RUBY_VERSION}\e[0m" | |
ruby_info = ruby_info | |
nest_info = "#{nest_level}" | |
obj_info = "\e[33m#{obj}\e[0m" | |
"[#{ruby_info}] #{nest_info}:(#{obj_info}) > " | |
end | |
Pry.prompt = [prompt_proc, prompt_proc] | |
# Load 'awesome_print' | |
begin | |
require 'awesome_print' | |
# The following line enables awesome_print for all pry output, | |
# and it also enables paging | |
Pry.config.print = proc {|output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output)} | |
# If you want awesome_print without automatic pagination, use the line below | |
# Pry.config.print = proc { |output, value| output.puts value.ai } | |
rescue LoadError => err | |
puts "gem install awesome_print" | |
end | |
# Load 'hirb' | |
begin | |
require 'hirb' | |
Pry.config.print = proc { |output, value| Hirb::View.view_or_page_output(value) || (output.puts "=> #{value.inspect}") } | |
Hirb.enable | |
rescue LoadError => err | |
puts "gem install hirb" | |
end | |
# Load plugins (only those I whitelist) | |
Pry.config.should_load_plugins = false | |
Pry.plugins['doc'].activate! | |
# Useful Collections | |
def a | |
Array.new(10){rand(100)} | |
end | |
def h | |
{ :foo => rand(100), :bar => rand(100) } | |
end | |
# Benchmarking | |
def bench(repetitions = 100, &block) | |
Benchmark.bm{|x| x.report{repetitions.times(&block)}} | |
end | |
if defined?(Rails) && Rails.env | |
def r | |
reload! | |
end | |
# Execute arbitrary SQL commands through the AR | |
def sql query | |
ActiveRecord::Base.connection.execute query | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment