irbtools 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/.document +5 -0
  2. data/.gitignore +21 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +44 -0
  5. data/Rakefile +40 -0
  6. data/VERSION +1 -0
  7. data/lib/irbtools.rb +210 -0
  8. metadata +200 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jan Lelis
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = irbtools
2
+
3
+ This is a meta gem which installs great irb gems for you and configures your irb.
4
+
5
+ == Setup
6
+
7
+ gem install irbtools
8
+
9
+ On linux, you also need the +xclip+ program (apt-get install xclip).
10
+
11
+ == Usage
12
+
13
+ To use it, put the following in your <tt>~/.irbrc</tt> file (this file is loaded everytime you start an irb):
14
+
15
+ require 'rubygems' # only needed in 1.8
16
+ require 'irbtools'
17
+
18
+ You could also just read and copy the irbtools.rb source file, tweak it and use it directly as <tt>.irbrc</tt>
19
+
20
+ == Features
21
+
22
+ See http;//rbjl.net/40 or read the commented source file: @lib/irbtools.rb@
23
+
24
+ === Included gems and libraries
25
+
26
+ 'wirble', # colors
27
+ 'hirb', # active record tables
28
+ 'fileutils', # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
29
+ 'zucker/env', # Info, OS, RubyVersion, RubyEngine
30
+ 'zucker/debug', # nice debug printing (q, o, c, .m, .d)
31
+ 'ap', # nice debug printing (ap)
32
+ 'yaml', # nice debug printing (y)
33
+ 'clipboard', # easy clipboard access (copy & paste)
34
+ 'guessmethod', # automatically correct typos (method_missing hook)
35
+ 'drx', # nice tk object inspector (.see)
36
+ 'interactive_editor', # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
37
+ 'coderay', # some nice colorful display ;)
38
+ 'irb_rocket', # put result as comment instead of a new line!
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2010 Jan Lelis. See LICENSE for details.
43
+
44
+ J-_-L
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "irbtools"
8
+ gem.summary = %Q{irbtools is a meta gem which installs some great irb gems for you and configures your irb.}
9
+ gem.description = %Q{irbtools is a meta gem which installs some great irb gems for you and configures your irb. Simply put a require 'irbtools' in the .irbrc file in your home directory.}
10
+ gem.email = "mail@janlelis.de"
11
+ gem.homepage = "http://github.com/janlelis/irbtools"
12
+ gem.authors = ["Jan Lelis"]
13
+ gem.requirements << 'You need to add http://merbi.st to your gem sources (irb_rocket)'
14
+ gem.add_dependency 'wirble'
15
+ gem.add_dependency 'hirb'
16
+ gem.add_dependency 'zucker', '>=7'
17
+ gem.add_dependency 'awesome_print'
18
+ gem.add_dependency 'g'
19
+ gem.add_dependency 'clipboard'
20
+ gem.add_dependency 'guessmethod'
21
+ gem.add_dependency 'drx'
22
+ gem.add_dependency 'interactive_editor'
23
+ gem.add_dependency 'coderay'
24
+ gem.add_dependency 'irb_rocket'
25
+ #gem.post_install_message 'irbtools'
26
+ end
27
+ Jeweler::GemcutterTasks.new
28
+ rescue LoadError
29
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
30
+ end
31
+
32
+ require 'rake/rdoctask'
33
+ Rake::RDocTask.new do |rdoc|
34
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
35
+
36
+ rdoc.rdoc_dir = 'doc'
37
+ rdoc.title = "irbtools #{version}"
38
+ rdoc.rdoc_files.include('README*')
39
+ rdoc.rdoc_files.include('lib/**/*.rb')
40
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/lib/irbtools.rb ADDED
@@ -0,0 +1,210 @@
1
+ # encoding: utf-8
2
+
3
+ # required gems: wirble hirb zucker awesome_print g clipboard guessmethod drx interactive_editory coderay irb_rocket
4
+
5
+ # either use this file as .irbrc or require 'irbtools' in your .irbrc
6
+
7
+ # # # # #
8
+ # load libraries
9
+ irb_libs = ['rubygems',
10
+ 'wirble', # colors
11
+ 'hirb', # active record tables
12
+ 'fileutils', # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
13
+ 'zucker/env', # Info, OS, RubyVersion, RubyEngine
14
+ 'zucker/debug', # nice debug printing (q, o, c, .m, .d)
15
+ 'ap', # nice debug printing (ap)
16
+ 'yaml', # nice debug printing (y)
17
+ 'g', # nice debug printing (g) - MacOS only :/
18
+ 'clipboard', # easy clipboard access (copy & paste)
19
+ 'guessmethod', # automatically correct typos (method_missing hook)
20
+ 'drx', # nice tk object inspector (.see)
21
+ 'interactive_editor', # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
22
+ 'coderay', # some nice colorful display ;)
23
+ 'irb_rocket', # put result as comment instead of a new line!
24
+ # 'zucker/all' # see rubyzucker.info
25
+ ]
26
+
27
+ irb_libs.each{ |lib|
28
+ begin
29
+ require lib
30
+
31
+ case lib
32
+ when 'wirble'
33
+ Wirble.init
34
+ Wirble.colorize
35
+
36
+ when 'hirb'
37
+ Hirb::View.enable
38
+
39
+ when 'zucker/env'
40
+ include OS # linux?, windows?, ...
41
+ Zucker.more_aliases! # RV, RE
42
+
43
+ when 'fileutils'
44
+ include FileUtils::Verbose
45
+
46
+ when 'clipboard'
47
+ def copy(str)
48
+ Clipboard.copy(str)
49
+ end
50
+
51
+ def paste
52
+ Clipboard.paste
53
+ end
54
+
55
+ def copy_session
56
+ require 'open3'
57
+ Open3.popen3('irb'){ |i,o,e|
58
+ i.puts session_history + "\nexit"
59
+ o.read
60
+ #copy o.read
61
+ }
62
+ # "The session history has been copied to the clipboard."
63
+ end
64
+
65
+ def copy_input
66
+ copy session_history
67
+ "The session input history has been copied to the clipboard."
68
+ end
69
+ alias copy_session_input copy_input
70
+
71
+ def copy_output
72
+ copy context.instance_variable_get(:@eval_history_values).inspect.gsub(/^\d+ (.*)/, '\1')
73
+ "The session output history has been copied to the clipboard."
74
+ end
75
+ alias copy_session_output copy_output
76
+
77
+ when 'coderay'
78
+ def colorize(string)
79
+ puts CodeRay.scan( string, :ruby ).term
80
+ end
81
+
82
+ def ray(path)
83
+ puts CodeRay.scan( File.read(path), :ruby ).term
84
+ end
85
+
86
+ end
87
+
88
+ rescue LoadError => err
89
+ warn "Couldn't load an irb library: #{err}"
90
+ end
91
+ }
92
+
93
+ # # # # #
94
+ # shortcuts & helpers
95
+
96
+ # shows the contents of your current directory (more such commands available by FileUtils)
97
+ def ls(path='.')
98
+ Dir[ File.join path, '*' ].map{|res| res =~ /^#{path}\/?/; $' }
99
+ end
100
+ alias dir ls
101
+
102
+ # patch cd so that it also shows the current directory
103
+ def cd(*args)
104
+ FileUtils::Verbose.cd *args
105
+ ls
106
+ end
107
+
108
+ # read file contents (also see ray for ruby source files ;) )
109
+ def cat(path)
110
+ File.read path
111
+ end
112
+
113
+ # allows concise syntax like rq:mathn
114
+ def rq(lib)
115
+ require lib.to_s
116
+ end
117
+
118
+ # returns the last lines, needed for some copy_ methods
119
+ def session_history(number_of_lines = context.instance_variable_get(:@line_no) )
120
+ Readline::HISTORY.entries[-number_of_lines...-1]*"\n"
121
+ end
122
+
123
+ # restart irb
124
+ def reset! # restart irb
125
+ exec$0
126
+ end
127
+
128
+ def ruby_version(which = nil)
129
+ # test if installed
130
+ unless `rvm -v` =~ /Seguin/
131
+ raise 'Ruby Version Manager must be installed to use this command'
132
+ end
133
+
134
+ # show rubies if called without options
135
+ if !which
136
+ puts 'Availabe Rubies: ' +
137
+ `rvm list`.scan( /^(?: |=>) (.*) \[/ )*", "
138
+ return
139
+ end
140
+
141
+ # get irb suffix
142
+ rv = `rvm use #{which}` # e.g. => "\ninfo: Using ruby 1.9.2 p0\n"
143
+ # it does not change the ruby for the current user
144
+ rv =~ /^.*Using(.*)\n/
145
+
146
+ # if ruby is found, start it
147
+ if $1
148
+ irbname = $0 + $1.tr(' ', '-') + '@global'
149
+ exec irbname
150
+ else
151
+ puts "Sorry, that Ruby version could not be found."
152
+ end
153
+ end
154
+ alias use ruby_version
155
+
156
+ # # # # #
157
+ # irb options
158
+ IRB.conf[:AUTO_INDENT] = true # simple auto indent
159
+ IRB.conf[:EVAL_HISTORY] = 42424242424242424242 # creates the special __ variable
160
+ IRB.conf[:SAVE_HISTORY] = 2000 # how many lines will go to ~/.irb_history
161
+
162
+ # prompt
163
+ IRB.conf[:PROMPT].merge!({:IRBTOOLS => {
164
+ :PROMPT_I => ">> ", # normal
165
+ :PROMPT_N => "| ", # indenting
166
+ :PROMPT_C => "(>>) ", # continuing a statement
167
+ :PROMPT_S => "%l> ", # continuing a string
168
+ :RETURN => "=> %s \n",
169
+ :AUTO_INDENT => true,
170
+ }})
171
+
172
+ IRB.conf[:PROMPT_MODE] = :IRBTOOLS
173
+
174
+ # # # # #
175
+ # workarounds
176
+
177
+ # patch exec (irb_rocket bug)
178
+ if IRB.const_defined? :CaptureIO
179
+ module Kernel
180
+ alias original_exec exec
181
+ def exec(*args)
182
+ STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
183
+ STDERR.reopen(IRB::CaptureIO.streams[:stderr])
184
+ original_exec *args
185
+ end
186
+ end
187
+
188
+ module IRB
189
+ class CaptureIO
190
+ def self.streams
191
+ {
192
+ :stdout => @@current_capture.instance_variable_get( :@out ),
193
+ :stderr => @@current_capture.instance_variable_get( :@err ),
194
+ }
195
+ end
196
+
197
+ alias original_capture capture
198
+ def capture(&block)
199
+ @@current_capture = self
200
+ original_capture &block
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+ # # # # #
207
+ # done :)
208
+ puts "Welcome to IRB. You are using #{RUBY_DESCRIPTION}. Have fun ;)"
209
+
210
+ # J-_-L
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irbtools
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jan Lelis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-05 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: wirble
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: hirb
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: zucker
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 7
56
+ version: "7"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: awesome_print
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ type: :runtime
71
+ version_requirements: *id004
72
+ - !ruby/object:Gem::Dependency
73
+ name: g
74
+ prerelease: false
75
+ requirement: &id005 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ type: :runtime
84
+ version_requirements: *id005
85
+ - !ruby/object:Gem::Dependency
86
+ name: clipboard
87
+ prerelease: false
88
+ requirement: &id006 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ type: :runtime
97
+ version_requirements: *id006
98
+ - !ruby/object:Gem::Dependency
99
+ name: guessmethod
100
+ prerelease: false
101
+ requirement: &id007 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ type: :runtime
110
+ version_requirements: *id007
111
+ - !ruby/object:Gem::Dependency
112
+ name: drx
113
+ prerelease: false
114
+ requirement: &id008 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ type: :runtime
123
+ version_requirements: *id008
124
+ - !ruby/object:Gem::Dependency
125
+ name: interactive_editor
126
+ prerelease: false
127
+ requirement: &id009 !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ type: :runtime
136
+ version_requirements: *id009
137
+ - !ruby/object:Gem::Dependency
138
+ name: coderay
139
+ prerelease: false
140
+ requirement: &id010 !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ type: :runtime
149
+ version_requirements: *id010
150
+ description: irbtools is a meta gem which installs some great irb gems for you and configures your irb. Simply put a require 'irbtools' in the .irbrc file in your home directory.
151
+ email: mail@janlelis.de
152
+ executables: []
153
+
154
+ extensions: []
155
+
156
+ extra_rdoc_files:
157
+ - LICENSE
158
+ - README.rdoc
159
+ files:
160
+ - .document
161
+ - .gitignore
162
+ - LICENSE
163
+ - README.rdoc
164
+ - Rakefile
165
+ - VERSION
166
+ - lib/irbtools.rb
167
+ has_rdoc: true
168
+ homepage: http://github.com/janlelis/irbtools
169
+ licenses: []
170
+
171
+ post_install_message: irbtools :)
172
+ rdoc_options:
173
+ - --charset=UTF-8
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ segments:
182
+ - 0
183
+ version: "0"
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ segments:
190
+ - 0
191
+ version: "0"
192
+ requirements:
193
+ - You need to add http://merbi.st to your gem sources (irb_rocket)
194
+ rubyforge_project:
195
+ rubygems_version: 1.3.7
196
+ signing_key:
197
+ specification_version: 3
198
+ summary: irbtools is a meta gem which installs some great irb gems for you and configures your irb.
199
+ test_files: []
200
+