Added pryrc and awesome_print configuration, updated README
This commit is contained in:
parent
0d42f4dd9d
commit
3697ebd799
22
README.md
22
README.md
@ -43,6 +43,19 @@ feel free to edit them:
|
||||
ae # alias edit
|
||||
ar # alias reload
|
||||
|
||||
Setup for Pry
|
||||
---
|
||||
Pry (http://pry.github.com/) offers a much better out of the box IRB experience
|
||||
with colors, tab completion, and lots of other tricks. You should:
|
||||
|
||||
gem install pry
|
||||
gem install awesome_print
|
||||
ln -s ~/.dotfiles/irb/pryrc ~/.pryrc
|
||||
ln -s ~/.dotfiles/irb/aprc ~/.aprc
|
||||
|
||||
The pryrc included here also offers some nice commands like 'clear', 'sql', and etc
|
||||
Look at the pryrc to see a list of commands or just type 'help' from pry.
|
||||
|
||||
Setup for Vim
|
||||
---
|
||||
To use the vim files:
|
||||
@ -76,6 +89,8 @@ These are things I use every day to be insanely productive. Hope you like em.
|
||||
* Apple-k and Apple-K to type underscores and dashes, since they are so common in code but so far away from home row
|
||||
* yw - remapped to yaw, meaning yanking a word will yank the entire word no matter where your cursor is
|
||||
* W - write a file (instead of :w, saving you keystrokes for the most common vim operation)
|
||||
* gcc (comment a line) via tComment, and gcp custom alias to comment a paragraph
|
||||
* Cc - (Current command) copies the command under your cursor and executes it in vim. Great for testing single line changes to vimrc.
|
||||
|
||||
Setup for Git
|
||||
---
|
||||
@ -117,10 +132,11 @@ I can't take credit for all of this. The vim files are a combination of
|
||||
work by tpope, scrooloose, and many hours of scouring blogs, vimscripts,
|
||||
and other places for the cream of the crop of vim and bash awesomeness.
|
||||
|
||||
TODO
|
||||
COMING SOON
|
||||
===
|
||||
I started migrating to tpope's pathogen, but only a few plugins are
|
||||
currently under vim/bundles.
|
||||
* Full migration to tpope's pathogen for all plugins
|
||||
* Better isolation of customizations in smaller chunks
|
||||
* Automatic setup script to symlink all dotfiles, or just some selectively
|
||||
|
||||
For more tips and tricks
|
||||
===
|
||||
|
24
irb/aprc
Normal file
24
irb/aprc
Normal file
@ -0,0 +1,24 @@
|
||||
AwesomePrint.defaults = {
|
||||
:indent => 2,
|
||||
:sort_keys => true,
|
||||
:color => {
|
||||
:args => :greenish,
|
||||
:array => :pale,
|
||||
:bigdecimal => :blue,
|
||||
:class => :yellow,
|
||||
:date => :greenish,
|
||||
:falseclass => :red,
|
||||
:fixnum => :blue,
|
||||
:float => :blue,
|
||||
:hash => :pale,
|
||||
:keyword => :cyan,
|
||||
:method => :purpleish,
|
||||
:nilclass => :red,
|
||||
:string => :yellowish,
|
||||
:struct => :pale,
|
||||
:symbol => :cyanish,
|
||||
:time => :greenish,
|
||||
:trueclass => :green,
|
||||
:variable => :cyanish
|
||||
}
|
||||
}
|
150
irb/pryrc
Normal file
150
irb/pryrc
Normal file
@ -0,0 +1,150 @@
|
||||
# === EDITOR ===
|
||||
Pry.editor = 'vi'
|
||||
|
||||
# === CUSTOM PROMPT ===
|
||||
Pry.prompt = [proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }]
|
||||
|
||||
# == PLUGINS ===
|
||||
# awesome_print gem: great syntax colorized printing
|
||||
# look at ~/.aprc for more settings for awesome_print
|
||||
begin
|
||||
require 'awesome_print'
|
||||
Pry.config.print = proc { |output, value| output.puts value.ai }
|
||||
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
|
||||
TERM_TOKEN_COLORS = {
|
||||
:attribute_name => '33',
|
||||
:attribute_value => '31',
|
||||
:binary => '1;35',
|
||||
:char => {
|
||||
:self => '36', :delimiter => '34'
|
||||
},
|
||||
:class => '1;35',
|
||||
:class_variable => '36',
|
||||
:color => '32',
|
||||
:comment => '37',
|
||||
:complex => '34',
|
||||
:constant => ['34', '4'],
|
||||
:decoration => '35',
|
||||
:definition => '1;32',
|
||||
:directive => ['32', '4'],
|
||||
:doc => '46',
|
||||
:doctype => '1;30',
|
||||
:doc_string => ['31', '4'],
|
||||
:entity => '33',
|
||||
:error => ['1;33', '41'],
|
||||
:exception => '1;31',
|
||||
:float => '1;35',
|
||||
:function => '1;34',
|
||||
:global_variable => '42',
|
||||
:hex => '1;36',
|
||||
:include => '33',
|
||||
:integer => '1;34',
|
||||
:key => '35',
|
||||
:label => '1;15',
|
||||
:local_variable => '33',
|
||||
:octal => '1;35',
|
||||
:operator_name => '1;29',
|
||||
:predefined_constant => '1;36',
|
||||
:predefined_type => '1;30',
|
||||
:predefined => ['4', '1;34'],
|
||||
:preprocessor => '36',
|
||||
:pseudo_class => '34',
|
||||
:regexp => {
|
||||
:self => '31',
|
||||
:content => '31',
|
||||
:delimiter => '1;29',
|
||||
:modifier => '35',
|
||||
:function => '1;29'
|
||||
},
|
||||
:reserved => '1;31',
|
||||
:shell => {
|
||||
:self => '42',
|
||||
:content => '1;29',
|
||||
:delimiter => '37',
|
||||
},
|
||||
:string => {
|
||||
:self => '36',
|
||||
:modifier => '1;32',
|
||||
:escape => '1;36',
|
||||
:delimiter => '1;32',
|
||||
},
|
||||
:symbol => '1;31',
|
||||
:tag => '34',
|
||||
:type => '1;34',
|
||||
:value => '36',
|
||||
:variable => '34',
|
||||
|
||||
:insert => '42',
|
||||
:delete => '41',
|
||||
:change => '44',
|
||||
:head => '45'
|
||||
}
|
||||
|
||||
module CodeRay
|
||||
module Encoders
|
||||
class Term < Encoder
|
||||
# override old colors
|
||||
TERM_TOKEN_COLORS.each_pair do |key, value|
|
||||
TOKEN_COLORS[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user