-
-
Save chussenot/5467243 to your computer and use it in GitHub Desktop.
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
# vim: se ft=ruby : | |
# ${HOME}/.pryrc | |
# https://github.com/carlhuda/bundler/issues/183#issuecomment-1149953 | |
if defined?(::Bundler) || File.exists?('Gemfile') | |
global_gemset = ENV['GEM_PATH'].split(':').grep(%r{ruby.*@global|gemsets/global}).first | |
if global_gemset | |
all_global_gem_paths = Dir.glob("#{global_gemset}/gems/*") | |
all_global_gem_paths.each do |p| | |
gem_path = "#{p}/lib" | |
$LOAD_PATH << gem_path | |
end | |
end | |
end | |
warn "loading global pryrc" | |
# see http://lucapette.com/pry/pry-everywhere/ | |
# vim FTW | |
Pry.config.editor = "gvim --nofork" | |
# My pry is polite | |
Pry.config.hooks.add_hook(:after_session, :say_goodbye) do | |
puts "bye-bye" | |
end | |
# Prompt with ruby version | |
Pry.prompt = [proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }] | |
%w[awesome_print pry-doc pry-nav].each do |gem| | |
begin | |
require gem | |
if gem == "pry-nav" | |
Pry.commands.alias_command 'c', 'continue' | |
Pry.commands.alias_command 's', 'step' | |
Pry.commands.alias_command 'n', 'next' | |
end | |
rescue LoadError | |
warn "could not load #{gem}" | |
end | |
end | |
# Toys methods | |
# Stealed from https://gist.github.com/807492 | |
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 | |
# LOOKSEE | |
begin | |
warn "loading looksee" | |
require "looksee" | |
module PryLookseeCompatibility | |
def ls *args | |
if Pry.color | |
Pry.color = false | |
p super | |
Pry.color = true | |
nil | |
else | |
super | |
end | |
end | |
end | |
Object.send(:include, PryLookseeCompatibility) | |
rescue LoadError | |
warn "could not load looksee!" | |
end | |
# loading rails configuration if it is running as a rails console | |
if defined?(Rails) && Rails.env && File.exists?(File.dirname(__FILE__) + '/.railsrc') | |
warn "loading #{File.dirname(__FILE__) + '/.railsrc'}" | |
load File.dirname(__FILE__) + '/.railsrc' | |
end | |
if File.exists?(File.expand_path('.pryrc')) && File.expand_path('.pryrc') != __FILE__ | |
warn "loading #{File.expand_path('.pryrc')}" | |
load File.expand_path('.pryrc') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment