2011-12-06 16:40:44 +08:00
|
|
|
# === EDITOR ===
|
|
|
|
Pry.editor = 'vi'
|
|
|
|
|
2012-05-20 05:19:32 +08:00
|
|
|
# == Pry-Nav - Using pry as a debugger ==
|
2012-05-31 07:31:54 +08:00
|
|
|
Pry.commands.alias_command 'c', 'continue' rescue nil
|
|
|
|
Pry.commands.alias_command 's', 'step' rescue nil
|
|
|
|
Pry.commands.alias_command 'n', 'next' rescue nil
|
2012-05-20 05:19:32 +08:00
|
|
|
|
2011-12-06 16:40:44 +08:00
|
|
|
# === CUSTOM PROMPT ===
|
2011-12-13 16:13:25 +08:00
|
|
|
# This prompt shows the ruby version (useful for RVM)
|
2011-12-06 16:40:44 +08:00
|
|
|
Pry.prompt = [proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }]
|
|
|
|
|
2011-12-13 16:13:25 +08:00
|
|
|
# === Listing config ===
|
|
|
|
# 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 = :green
|
|
|
|
Pry.config.ls.protected_method_color = :yellow
|
|
|
|
Pry.config.ls.private_method_color = :bright_black
|
|
|
|
|
2011-12-06 16:40:44 +08:00
|
|
|
# == PLUGINS ===
|
|
|
|
# awesome_print gem: great syntax colorized printing
|
|
|
|
# look at ~/.aprc for more settings for awesome_print
|
|
|
|
begin
|
|
|
|
require 'awesome_print'
|
2011-12-20 17:34:20 +08:00
|
|
|
# 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 }
|
2011-12-06 16:40:44 +08:00
|
|
|
rescue LoadError => err
|
|
|
|
puts "gem install awesome_print # <-- highly recommended"
|
|
|
|
end
|
|
|
|
|
|
|
|
# === CUSTOM COMMANDS ===
|
|
|
|
# from: https://gist.github.com/1297510
|
|
|
|
default_command_set = Pry::CommandSet.new do
|
|
|
|
command "copy", "Copy argument to the clip-board" do |str|
|
|
|
|
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
|
|
|
|
end
|
|
|
|
|
|
|
|
command "clear" do
|
|
|
|
system 'clear'
|
|
|
|
if ENV['RAILS_ENV']
|
|
|
|
output.puts "Rails Environment: " + ENV['RAILS_ENV']
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
command "sql", "Send sql over AR." do |query|
|
|
|
|
if ENV['RAILS_ENV'] || defined?(Rails)
|
|
|
|
pp ActiveRecord::Base.connection.select_all(query)
|
|
|
|
else
|
|
|
|
pp "No rails env defined"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
command "caller_method" do |depth|
|
|
|
|
depth = depth.to_i || 1
|
|
|
|
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first
|
|
|
|
file = Regexp.last_match[1]
|
|
|
|
line = Regexp.last_match[2].to_i
|
|
|
|
method = Regexp.last_match[3]
|
|
|
|
output.puts [file, line, method]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Pry.config.commands.import default_command_set
|
|
|
|
|
|
|
|
|
|
|
|
# === CONVENIENCE METHODS ===
|
|
|
|
# Stolen from https://gist.github.com/807492
|
|
|
|
# Use Array.toy or Hash.toy to get an array or hash to play with
|
|
|
|
class Array
|
|
|
|
def self.toy(n=10, &block)
|
|
|
|
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Hash
|
|
|
|
def self.toy(n=10)
|
|
|
|
Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# === COLOR CUSTOMIZATION ===
|
|
|
|
# Everything below this line is for customizing colors, you have to use the ugly
|
|
|
|
# color codes, but such is life.
|
|
|
|
CodeRay.scan("example", :ruby).term # just to load necessary files
|
|
|
|
# Token colors pulled from: https://github.com/rubychan/coderay/blob/master/lib/coderay/encoders/terminal.rb
|
2013-11-29 21:14:31 +08:00
|
|
|
|
|
|
|
$LOAD_PATH << File.dirname(File.realpath(__FILE__))
|
|
|
|
|
|
|
|
# In CodeRay >= 1.1.0 token colors are defined as pre-escaped ANSI codes
|
2013-11-29 21:34:10 +08:00
|
|
|
if Gem::Version.new(CodeRay::VERSION) >= Gem::Version.new('1.1.0')
|
2013-11-29 21:14:31 +08:00
|
|
|
require "escaped_colors"
|
|
|
|
else
|
|
|
|
require "unescaped_colors"
|
|
|
|
end
|
2011-12-06 16:40:44 +08:00
|
|
|
|
|
|
|
module CodeRay
|
2014-08-27 11:57:16 +08:00
|
|
|
module Encoders
|
|
|
|
class Terminal < Encoder
|
|
|
|
# override old colors
|
|
|
|
TERM_TOKEN_COLORS.each_pair do |key, value|
|
|
|
|
TOKEN_COLORS[key] = value
|
|
|
|
end
|
2011-12-06 16:40:44 +08:00
|
|
|
end
|
2014-08-27 11:57:16 +08:00
|
|
|
end
|
2011-12-06 16:40:44 +08:00
|
|
|
end
|