Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gemify general helpers/rvm stuff ("every_day_irb", "rvm_loader")

  • Loading branch information...
commit b2c624cf77ecd412eb9a854fb21410b62f7bb271 1 parent 65f40e0
@janlelis authored
View
12 README.rdoc
@@ -1,5 +1,5 @@
= irbtools
-This is a meta gem which installs useful irb gems and configures your irb. It has a modular structure and supports multiple library-loading mechanisms like via <tt>autoload</tt> or threads.
+This is a meta gem that installs useful irb gems and configures your irb. It has a modular structure and supports multiple library-loading mechanisms like via <tt>autoload</tt> or threads.
== Setup
gem install irbtools
@@ -62,6 +62,7 @@ See http://rbjl.net/40-irbtools-release-the-power-of-irb or read the commented s
* wirb[https://github.com/janlelis/wirb/] colorize output
* hirb[http://tagaholic.me/2009/03/13/hirb-irb-on-the-good-stuff.html] (active record) tables and custom views for specific objects
* fancy_irb[https://github.com/janlelis/fancy_irb] put result as comment and more colorization
+* every_day_irb[https://github.com/janlelis/irbtools/tree/master/lib/every_day_irb.rb] helper methods that might be useful in every-day irb usage, e.g.: ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg
* clipboard[http://github.com/janlelis/clipboard] easy clipboard access (copy & paste)
* interactive_editor[https://github.com/jberkel/interactive_editor] lets you open vim, hack something, and it gets loaded into the current session, also possible: yaml object editing
* sketches[http://sketches.rubyforge.org/] another, more flexible "start editor and it gets loaded into your irb session" plugin
@@ -76,15 +77,6 @@ See http://rbjl.net/40-irbtools-release-the-power-of-irb or read the commented s
* guessmethod[http://guessmethod.rubyforge.org/] automatically corrects typos (method_missing hook)
-=== Helper methods
-See the source for a description. These methods are defined directly by irbtools. Each gem may add its own helper methods.
-
-*General*: <tt>ls, cat, rq, rrq/rerequire, ld, session_history, reset!, clear, use_ruby/use, rubies, use_gemset/gemset, gemsets, dbg</tt>
-
-*Clipboard*: <tt>copy, paste, copy_input, copy_output</tt>
-
-*CodeRay*: <tt>colorize, ray</tt>
-
==== RVM
If you have RVM installed, you can switch your gemset or ruby with <tt>gemset</tt> and <tt>use</tt> (use <tt>gemsets</tt> and <tt>rubies</tt> to get a list). The gemset can be changed within the session, while changing ruby starts a new one. Please also note that you need to have installed irbtools for that ruby version. I recommend installing it in the <tt>global</tt> gemset.
View
30 Rakefile
@@ -2,37 +2,37 @@ require 'rake'
require 'rake/rdoctask'
require 'fileutils'
-def gemspec
- @gemspec ||= eval(File.read('irbtools.gemspec'), binding, 'irbtools.gemspec')
+def gemspec1
+ @gemspec1 ||= eval(File.read('irbtools.gemspec'), binding, 'irbtools.gemspec')
+end
+
+def gemspec2
+ @gemspec2 ||= eval(File.read('every_day_irb.gemspec'), binding, 'every_day_irb.gemspec')
end
desc "Build the gem"
task :gem => :gemspec do
sh "gem build irbtools.gemspec"
+ sh "gem build every_day_irb.gemspec"
FileUtils.mkdir_p 'pkg'
- FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
+ FileUtils.mv "#{gemspec1.name}-#{gemspec1.version}.gem", 'pkg'
+ FileUtils.mv "#{gemspec2.name}-#{gemspec2.version}.gem", 'pkg'
end
desc "Install the gem locally (without docs)"
task :install => :gem do
- sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
+ sh %{gem install pkg/#{gemspec2.name}-#{gemspec2.version} --no-rdoc --no-ri}
+ sh %{gem install pkg/#{gemspec1.name}-#{gemspec1.version} --no-rdoc --no-ri}
end
desc "Generate the gemspec"
task :generate do
- puts gemspec.to_ruby
+ puts gemspec1.to_ruby
+ puts gemspec2.to_ruby
end
desc "Validate the gemspec"
task :gemspec do
- gemspec.validate
-end
-
-Rake::RDocTask.new do |rdoc|
- version = File.exist?('VERSION') ? File.read('VERSION').chomp : ""
-
- rdoc.rdoc_dir = 'doc'
- rdoc.title = "irbtools #{version}"
- rdoc.rdoc_files.include('README*')
- rdoc.rdoc_files.include('lib/**/*.rb')
+ gemspec1.validate
+ gemspec2.validate
end
View
16 every_day_irb.gemspec
@@ -0,0 +1,16 @@
+# -*- encoding: utf-8 -*-
+require 'rubygems' unless defined? Gem
+
+Gem::Specification.new do |s|
+ s.name = 'every_day_irb'
+ s.version = File.read('VERSION').chomp
+
+ s.authors = ["Jan Lelis"]
+ s.summary = 'every_day_irb defines some helper methods that might be useful in irb.'
+ s.description = 'every_day_irb defines some helper methods that might be useful in every-day irb usage, e.g.: ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg'
+ s.email = 'mail@janlelis.de'
+ s.extra_rdoc_files = %w[LICENSE]
+ s.files = Dir.glob(%w[lib/every_day_irb.rb VERSION every_day_irb.gemspec])
+ s.homepage = 'http://github.com/janlelis/irbtools'
+ s.required_ruby_version = '>= 1.8.7'
+end
View
15 irbtools.gemspec
@@ -6,13 +6,12 @@ Gem::Specification.new do |s|
s.version = File.read('VERSION').chomp
s.authors = ["Jan Lelis"]
- s.date = %q{2011-03-28}
- s.summary = %q{irbtools is a meta gem which installs some useful irb gems and configures your irb.}
- s.description = %q{irbtools is a meta gem which installs some useful irb gems and configures your irb. Simply put a require 'irbtools' in the .irbrc file in your home directory.}
- s.email = %q{mail@janlelis.de}
+ s.summary = 'irbtools is a meta gem that installs useful irb gems and configures your irb.'
+ s.description = 'irbtools is a meta gem that installs useful irb gems and configures your irb. Simply put a require "irbtools" in the .irbrc file in your home directory.'
+ s.email = 'mail@janlelis.de'
s.extra_rdoc_files = %w[LICENSE README.rdoc]
- s.files = Dir.glob(%w[lib/**/*.rb ]) + %w{VERSION CHANGELOG Rakefile irbtools.gemspec}
- s.homepage = %q{http://github.com/janlelis/irbtools}
+ s.files = %w[lib/irbtools.rb lib/irbtools/configure.rb lib/irbtools/libraries.rb VERSION CHANGELOG Rakefile irbtools.gemspec]
+ s.homepage = 'http://github.com/janlelis/irbtools'
s.required_ruby_version = '>= 1.8.7'
s.add_dependency %q<fancy_irb>, ">= 0.6.5"
@@ -22,10 +21,12 @@ Gem::Specification.new do |s|
s.add_dependency %q<clipboard>, ">= 0.9.7"
s.add_dependency %q<coderay>, "~> 0.9"
s.add_dependency %q<boson>, ">= 0.3.3"
- s.add_dependency %q<wirb>, ">= 0.2.4"
+ s.add_dependency %q<wirb>, ">= 0.2.5"
s.add_dependency %q<interactive_editor>, ">= 0.0.8"
s.add_dependency %q<ori>, "~> 0.1.0"
s.add_dependency %q<sketches>, ">= 0"
s.add_dependency %q<g>, ">= 0"
s.add_dependency %q<methodfinder>, ">= 1.2.1"
+ s.add_dependency %q<rvm_loader>, ">= 1.0.0"
+ s.add_dependency %q<every_day_irb>, ">= #{ s.version }"
end
View
58 lib/irbtools/general.rb → lib/every_day_irb.rb
@@ -1,3 +1,9 @@
+# every_day_irb defines some helper methods that might be useful in every-day irb usage
+
+module EveryDayIrb
+ VERSION = File.read( File.dirname(__FILE__) + '/../VERSION' ).chomp
+end
+
# shows the contents of your current directory (more such commands available by FileUtils)
def ls(path='.')
Dir[ File.join( path, '*' )].map{|res| res =~ /^#{path}\/?/; $' }
@@ -60,58 +66,6 @@ def clear
system 'clear'
end
-# change ruby version (requires rvm)
-autoload :RVM, 'irbtools/rvm'
-
-def rubies
- RVM.current.list_strings
-end
-
-def use(which = nil) # TODO with gemsets?
- # show current ruby if called without options
- if !which
- return RVM.current.environment_name[/^.*@|.*$/].chomp('@')
- end
-
- # start ruby :)
- begin
- RVM.use! which.to_s
- rescue RVM::IncompatibleRubyError => err
- err.message =~ /requires (.*?) \(/
- rubies = RVM.current.list_strings
- if rubies.include? $1
- # remember history...
- run_irb = proc{ exec "#{ $1 } -S #{ $0 }" }
- if defined?(Ripl) && Ripl.instance_variable_get(:@shell) # ripl is running
- Ripl.shell.write_history if Ripl.shell.respond_to? :write_history
- run_irb.call
- else
- at_exit(&run_irb)
- exit
- end
- else
- warn "Sorry, that Ruby version could not be found (see rubies)!"
- end
- end
-end
-alias use_ruby use
-
-def gemsets
- RVM.current.gemset.list
-end
-
-def gemset(which = nil)
- if which
- if RVM.current.gemset.list.include? which.to_s
- RVM.use! RVM.current.environment_name.gsub /(@.*?$)|$/, "@#{ which }"
- else
- warn "Sorry, that gemset could not be found (see gemsets)!"
- end
- end
- RVM.current.gemset_name
-end
-alias use_gemset gemset
-
# load debugger, inspired by rdp
def dbg
begin
View
9 lib/irbtools.rb
@@ -39,7 +39,7 @@
# load: start
load_libraries_proc[ Irbtools.libraries[:start] ]
- # load : after_rc / sub-session
+ # load: after_rc / sub-session
if defined?(Ripl) && Ripl.started?
if defined? Ripl::AfterRc
Ripl.after_rcs += Irbtools.libraries[:after_rc]
@@ -54,18 +54,13 @@
}
end
- # load: autoload
+ # load: autoload hooks
Irbtools.libraries[:autoload].each{ |constant, lib|
gem lib
autoload constant, lib
Irbtools.send :library_loaded, lib
}
-
- # # # # #
- # general shortcuts & helper methods
- require File.expand_path('irbtools/general', File.dirname(__FILE__) )
-
# # # # #
# irb options
unless defined? Ripl
View
4 lib/irbtools/configure.rb
@@ -15,6 +15,8 @@
# # # # #
# define module methods
module Irbtools
+ VERSION = File.read( File.dirname(__FILE__) + '/../../VERSION' ).chomp
+
@lib_hooks = Hash.new{|h,k| h[k] = [] }
@libs = { :start => [], :after_rc => [], :autoload => [], :thread => {} }
@packages = []
@@ -89,8 +91,6 @@ def init
end
alias start init
end
-
- VERSION = ( File.read File.expand_path( '../../VERSION', File.dirname(__FILE__)) ).chomp
end
# # # # #
View
69 lib/irbtools/libraries.rb
@@ -24,7 +24,9 @@
Boson.start :verbose => false
end
-Irbtools.add_library :fileutils, :thread => 40 do # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
+Irbtools.add_library 'every_day_irb', :thread => 40 # ls, cat, rq, rrq, ld, session_history, reset!, clear, dbg, ...
+
+Irbtools.add_library :fileutils, :thread => 50 do # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
include FileUtils::Verbose
# patch cd so that it also shows the current directory
@@ -44,19 +46,19 @@ def cd( path = File.expand_path('~') )
end
end
-Irbtools.add_library 'zucker/debug', :thread => 50 # nice debug printing (q, o, c, .m, .d)
+Irbtools.add_library 'zucker/debug', :thread => 60 # nice debug printing (q, o, c, .m, .d)
-Irbtools.add_library 'ap', :thread => 60 # nice debug printing (ap)
+Irbtools.add_library 'ap', :thread => 70 # nice debug printing (ap)
-Irbtools.add_library 'wirb/wp', :thread => 70 # ap alternative (wp)
+Irbtools.add_library 'wirb/wp', :thread => 80 # ap alternative (wp)
-Irbtools.add_library 'g', :thread => 80 if OS.mac? # nice debug printing (g) - MacOS only :/
+Irbtools.add_library 'g', :thread => 90 if OS.mac? # nice debug printing (g) - MacOS only :/
-Irbtools.add_library 'interactive_editor', :thread => 90 # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
+Irbtools.add_library 'interactive_editor', :thread => 100 # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
-Irbtools.add_library 'sketches', :thread => 100 # another, more flexible "start editor and it gets loaded into your irb session" plugin
+Irbtools.add_library 'sketches', :thread => 110 # another, more flexible "start editor and it gets loaded into your irb session" plugin
-Irbtools.add_library :ori, :thread => 110 do # object oriented ri method
+Irbtools.add_library :ori, :thread => 120 do # object oriented ri method
class Object
# patch ori to also allow shell-like "Array#slice" syntax
def ri(*args)
@@ -125,4 +127,55 @@ def mf(*args, &block)
end
end
+Irbtools.add_library 'rvm_loader', :autoload => :RVM do
+ def rubies
+ RVM.current.list_strings
+ end
+
+ def use(which = nil) # TODO with gemsets?
+ # show current ruby if called without options
+ if !which
+ return RVM.current.environment_name[/^.*@|.*$/].chomp('@')
+ end
+
+ # start ruby :)
+ begin
+ RVM.use! which.to_s
+ rescue RVM::IncompatibleRubyError => err
+ err.message =~ /requires (.*?) \(/
+ rubies = RVM.current.list_strings
+ if rubies.include? $1
+ # remember history...
+ run_irb = proc{ exec "#{ $1 } -S #{ $0 }" }
+ if defined?(Ripl) && Ripl.instance_variable_get(:@shell) # ripl is running
+ Ripl.shell.write_history if Ripl.shell.respond_to? :write_history
+ run_irb.call
+ else
+ at_exit(&run_irb)
+ exit
+ end
+ else
+ warn "Sorry, that Ruby version could not be found (see rubies)!"
+ end
+ end
+ end
+ alias use_ruby use
+
+ def gemsets
+ RVM.current.gemset.list
+ end
+
+ def gemset(which = nil)
+ if which
+ if RVM.current.gemset.list.include? which.to_s
+ RVM.use! RVM.current.environment_name.gsub /(@.*?$)|$/, "@#{ which }"
+ else
+ warn "Sorry, that gemset could not be found (see gemsets)!"
+ end
+ end
+ RVM.current.gemset_name
+ end
+ alias use_gemset gemset
+end
+
# J-_-L
View
8 lib/irbtools/rvm.rb
@@ -1,8 +0,0 @@
-# test if installed
-unless rvm_path = ENV['rvm_path']
- raise 'Ruby Version Manager must be installed to use this command'
-end
-
-# load rvm ruby api
-$LOAD_PATH.unshift File.join(rvm_path, 'lib')
-require 'rvm'
Please sign in to comment.
Something went wrong with that request. Please try again.