Skip to content

Instantly share code, notes, and snippets.

@codemilan
Forked from edvardm/ruby-tools-install.sh
Created January 24, 2020 07:06
Show Gist options
  • Save codemilan/6bc91c12d6a086a7bff1f71f121125c3 to your computer and use it in GitHub Desktop.
Save codemilan/6bc91c12d6a086a7bff1f71f121125c3 to your computer and use it in GitHub Desktop.
script to install pry and some other nice tools for Ruby
#!/usr/bin/env bash
#
# Simple script to setup friendly environment for beginning Linux/Mac Ruby users
#
echo "installing pry and awesome_print"
gem install -q --no-ri --no-rdoc \
pry pry-doc pry-coolline awesome_print
# Nifty pry config copied from https://github.com/dotphiles/dotphiles/blob/master/ruby/aprc
PRYRC="$HOME/.pryrc"
if [ ! -f $PRYRC ]; then
echo "Writing a nice $PRYRC"
cat <<EOF > $PRYRC
# === CUSTOM PROMPT ===
# This prompt shows the ruby version (useful for RVM)
prompt_proc = lambda do |obj, nest_level, _|
ruby_info = ""
ruby_info << "#{Rails.version}@" if defined?(Rails)
ruby_info << RUBY_VERSION
ruby_info = "\e[32m#{ruby_info}\e[0m"
nest_info = "#{nest_level}"
obj_info = "\e[33m#{obj}\e[0m"
"[#{ruby_info}] #{nest_info}:(#{obj_info}) > "
end
Pry.prompt = [prompt_proc, prompt_proc]
# === 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
# === 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=7, &block)
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
end
end
class Hash
def self.toy(n=7)
Hash[(Array.toy(n) { |c| (96+(c+1)).chr.to_sym }).zip(Array.toy(n))]
end
end
# == PLUGINS ===
# awesome_print gem: great syntax colorized printing
# look at ~/.aprc for more settings for 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 # <-- highly recommended"
end
EOF
else
echo "$PRYRC found, refusing to overwrite"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment