Skip to content

Instantly share code, notes, and snippets.

@chucai
Forked from justin808/.pryrc
Last active August 29, 2015 14:06
Show Gist options
  • Save chucai/3de89668675f14b409a5 to your computer and use it in GitHub Desktop.
Save chucai/3de89668675f14b409a5 to your computer and use it in GitHub Desktop.
## Useful Collections
def a_array
(1..6).to_a
end
def a_hash
{hello: "world", free: "of charge"}
end
# Pry.config.pager = true
# Pry.config.editor = "emacs"
Pry.config.color = true
Pry.config.prompt = Pry::NAV_PROMPT
Pry.config.commands.alias_command "h", "hist -T 20", desc: "Last 20 commands"
Pry.config.commands.alias_command "hg", "hist -T 20 -G", desc: "Up to 20 commands matching expression"
Pry.config.commands.alias_command "hG", "hist -G", desc: "Commands matching expression ever used"
Pry.config.commands.alias_command "hr", "hist -r", desc: "hist -r <command number> to run a command"
begin
require 'awesome_print'
# Pry.config.print = proc { |output, value| output.puts value.ai }
AwesomePrint.pry!
rescue LoadError => err
puts "no awesome_print :("
end
my_hook = Pry::Hooks.new.add_hook(:before_session, :add_dirs_to_load_path) do
# adds the directories /spec and /test directories to the path if they exist and not already included
dir = `pwd`.chomp
dirs_added = []
%w(spec test).map{ |d| "#{dir}/#{d}" }.each do |p|
if File.exist?(p) && !$:.include?(p)
$: << p
dirs_added << p
end
end
puts "Added #{ dirs_added.join(", ") } to load path in ~/.pryrc." if dirs_added.present?
end
my_hook.exec_hook(:before_session)
puts "Loaded ~/.pryrc"
puts
puts "Helpful shortcuts:"
puts "h : hist -T 20 Last 20 commands"
puts "hg : hist -T 20 -G Up to 20 commands matching expression"
puts "hG : hist -G Commands matching expression ever used"
puts "hr : hist -r hist -r <command number> to run a command"
puts
puts "Samples variables"
puts "a_array : [1, 2, 3, 4, 5, 6]"
puts "a_hash : { hello: \"world\", free: \"of charge\" }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment