Last active
August 29, 2015 14:23
-
-
Save khebbie/6d387e07b2eab1999b10 to your computer and use it in GitHub Desktop.
My dotfiles for devbox (vagrant)
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
require 'active_support' | |
require 'active_support/core_ext' | |
# load a gem that may or may not be handled by bundler in your directory | |
# see links above for details on this | |
def unbundled_require gem | |
if defined?(::Bundler) | |
# Have to check for a version to avoid gems with dashes, e.g. pry-rails | |
spec_path = Dir.glob("#{Gem.dir}/specifications/#{gem}-[0-9]*.gemspec").last | |
if spec_path.nil? | |
warn "#{ANSI[:BOLD]}Couldn't find #{gem}#{ANSI[:RESET]}" | |
return | |
end | |
spec = Gem::Specification.load spec_path | |
spec.runtime_dependencies.each do |dependency| | |
puts "loading dependency #{dependency}" | |
# TODO: handle versions | |
unbundled_require dependency.name | |
end | |
spec.activate | |
end | |
begin | |
require gem | |
yield if block_given? | |
rescue Exception => err | |
warn "#{ANSI[:BOLD]}Couldn't load #{gem}: #{err}#{ANSI[:RESET]}" | |
end | |
end | |
if defined?(::Bundler) | |
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@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 | |
require 'rubygems' | |
require 'irb/completion' | |
# improved formatting for objects | |
unbundled_require 'awesome_print' do | |
AwesomePrint.irb! | |
end | |
begin | |
# start wirble (with color) | |
require 'wirble' | |
Wirble.init | |
Wirble.colorize | |
rescue LoadError | |
puts 'wirble not installed' | |
end | |
# begin | |
# require 'awesome_print' | |
# | |
# module AwesomePrintMongoid | |
# def self.included(base) | |
# base.send :alias_method, :printable_without_mongoid, :printable | |
# base.send :alias_method, :printable, :printable_with_mongoid | |
# end | |
# | |
# # Add Mongoid class names to the dispatcher pipeline. | |
# #------------------------------------------------------------------------------ | |
# def printable_with_mongoid(object) | |
# printable = printable_without_mongoid(object) | |
# return printable if !defined?(Mongoid::Document) | |
# | |
# if printable == :self | |
# if object.is_a?(Mongoid::Document) | |
# printable = :mongoid_instance | |
# end | |
# elsif printable == :class && object.ancestors.include?(Mongoid::Document) | |
# printable = :mongoid_class | |
# end | |
# printable | |
# end | |
# | |
# # Format Mongoid instance object. | |
# #------------------------------------------------------------------------------ | |
# def awesome_mongoid_instance(object) | |
# return object.inspect if !defined?(ActiveSupport::OrderedHash) | |
# | |
# data = object.fields.keys.sort_by{|k| k}.inject(ActiveSupport::OrderedHash.new) do |hash, name| | |
# hash[name] = object[name] | |
# hash | |
# end | |
# "#{object} " + awesome_hash(data) | |
# end | |
# | |
# # Format Mongoid class object. | |
# #------------------------------------------------------------------------------ | |
# def awesome_mongoid_class(object) | |
# return object.inspect if !defined?(ActiveSupport::OrderedHash) | |
# | |
# data = object.fields.sort_by{|k| k}.inject(ActiveSupport::OrderedHash.new) do |hash, c| | |
# hash[c.first] = (c.last.type || "undefined").to_s.underscore.intern | |
# hash | |
# end | |
# "class #{object} < #{object.superclass} " << awesome_hash(data) | |
# end | |
# end | |
# | |
# AwesomePrint.send(:include, AwesomePrintMongoid) | |
# rescue LoadError | |
# end | |
begin | |
require 'hirb' | |
extend Hirb::Console | |
Hirb::View.enable | |
rescue LoadError | |
end | |
begin | |
require 'interactive_editor' | |
rescue LoadError | |
end | |
# Load readline and completion for irb | |
IRB.conf[:USE_READLINE] = true | |
IRB.conf[:AUTO_INDENT] = true | |
IRB.conf[:SAVE_HISTORY] = 1000 | |
IRB.conf[:EVAL_HISTORY] = 200 | |
IRB.conf[:PROMPT_MODE] = :SIMPLE | |
# local_methods shows methods that are only available for a given object. | |
class Object | |
def local_methods | |
self.methods.sort - self.class.superclass.methods | |
end | |
def interesting_methods | |
case self.class | |
when Class | |
self.public_methods.sort - Object.public_methods | |
when Module | |
self.public_methods.sort - Module.public_methods | |
else | |
self.public_methods.sort - Object.new.public_methods | |
end | |
end | |
end | |
module Kernel | |
def require_relative(file) | |
$:.unshift Dir.pwd | |
require file | |
end | |
end | |
# Log to STDOUT if in Rails | |
if ENV.include?('RAILS_ENV') | |
if !Object.const_defined?('RAILS_DEFAULT_LOGGER') | |
require 'logger' | |
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT)) | |
end | |
def sql(query) | |
ActiveRecord::Base.connection.select_all(query) | |
end | |
if ENV['RAILS_ENV'] == 'test' | |
require 'test/test_helper' | |
end | |
elsif defined?(Rails) && !Rails.env.nil? && defined?(ActiveRecord) | |
# for rails 3 | |
if Rails.logger | |
Rails.logger = Logger.new(STDOUT) | |
ActiveRecord::Base.logger = Rails.logger | |
end | |
if Rails.env == 'test' | |
require 'test/test_helper' | |
end | |
else | |
# nothing to do | |
end | |
if defined?(Mongoid) | |
Mongoid.config.logger = Logger.new($stdout) | |
end | |
# annotate column names of an AR model | |
def show(obj) | |
y(obj.send("column_names")) | |
end | |
# Copious output helper | |
def less | |
spool_output('less') | |
end | |
def most | |
spool_output('most') | |
end | |
def spool_output(spool_cmd) | |
require 'stringio' | |
$stdout, sout = StringIO.new, $stdout | |
yield | |
$stdout, str_io = sout, $stdout | |
IO.popen(spool_cmd, 'w') do |f| | |
f.write str_io.string | |
f.flush | |
f.close_write | |
end | |
end | |
# Simple regular expression helper | |
# show_regexp - stolen from the pickaxe | |
def show_regexp(a, re) | |
if a =~ re | |
"#{$`}<<#{$&}>>#{$'}" | |
else | |
"no match" | |
end | |
end | |
# Convenience method on Regexp so you can do | |
# /an/.show_match("banana") | |
class Regexp | |
def show_match(a) | |
show_regexp(a, self) | |
end | |
end | |
# Reloads a file just as you would require it. | |
def reload(filename) | |
$".delete(filename + ".rb") | |
require(filename) | |
end |
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
# Set up the prompt | |
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history: | |
HISTSIZE=1000 | |
SAVEHIST=1000 | |
HISTFILE=~/.zsh_history | |
# some more ls aliases | |
alias ll='ls -alF' | |
alias la='ls -A' | |
alias l='ls -CF' | |
# ack-grep | |
alias ack='ack-grep' | |
# Stacktrace friendly command for tailing syslog | |
alias systail="sudo tail -f /var/log/syslog | sed 's/#012/\n\t/g' | grep -v 'postgres'" | |
# Add an "alert" alias for long running commands. Use like so: | |
# sleep 10; alert | |
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' | |
PATH="$PATH:/vagrant/development/misc/bin" | |
PATH="$PATH:/home/vagrant/.gem/ruby/2.1.0/bin" | |
export VAGRANT_HOST_USER=khebbie | |
function be(){ | |
if [[ -a Gemfile ]]; then | |
bundle exec $* | |
else | |
command $* | |
fi | |
} | |
alias rake='be rake' | |
alias cap='be cap' | |
alias rspec='be rspec' |
git clone git@github.com:tarjoilija/zgen.git ${HOME}/proj/zgen
if getting
zsh compinit: insecure directories, run compaudit for list.
this will fix it
compaudit | xargs chmod g-w
wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
pip install pgcli
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bundle exec gem install awesome_print
bundle exec gem install hirb
bundle exec gem install wirble