irbtools 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.rdoc +7 -6
  2. data/VERSION +1 -1
  3. data/lib/irbtools.rb +40 -201
  4. metadata +4 -4
data/README.rdoc CHANGED
@@ -15,11 +15,14 @@ This is a meta gem which installs great irb gems for you and configures your irb
15
15
  To use it, put the following in your <tt>~/.irbrc</tt> file (this file is loaded everytime you start an irb):
16
16
 
17
17
  require 'rubygems' # only needed in 1.8
18
+
18
19
  require 'irbtools'
20
+ # Irbtools.libs is a set of libraries and gems which get loaded. You can manually add or remove some.
21
+ Irbtools.load
19
22
 
20
23
  If it does not exists, just create a new one.
21
24
 
22
- You could also just read and copy the irbtools.rb source file, tweak it and use it directly as <tt>.irbrc</tt>
25
+ You could also just read and copy the irbtools.rb and irbtools/init.rb source files, tweak them and use them directly as <tt>.irbrc</tt>
23
26
 
24
27
  == Features
25
28
 
@@ -43,13 +46,11 @@ See http;//rbjl.net/40 or read the commented source file: lib/irbtools.rb
43
46
  == TODO
44
47
 
45
48
  * Make guessmethod 1.9 compatible
49
+ * Fix Clipboard Windows issues
46
50
  * ...
51
+
47
52
  == Copyright
48
53
 
49
- Copyright (c) 2010 Jan Lelis. See LICENSE for details.
54
+ Copyright (c) 2010 Jan Lelis, http://rbjl.net. See LICENSE for details.
50
55
 
51
56
  J-_-L
52
-
53
- blogartikel
54
- windows
55
- outcommentable
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/lib/irbtools.rb CHANGED
@@ -1,216 +1,55 @@
1
1
  # encoding: utf-8
2
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
- require 'zucker/env' # Info, OS, RubyVersion, RubyEngine
8
-
9
- # # # # #
10
- # load libraries
11
- irb_libs = ['rubygems',
12
- 'wirble', # colors
13
- 'hirb', # active record tables
14
- 'fileutils', # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
15
- 'zucker/debug', # nice debug printing (q, o, c, .m, .d)
16
- 'ap', # nice debug printing (ap)
17
- 'yaml', # nice debug printing (y)
18
- 'g', # nice debug printing (g) - MacOS only :/
19
- 'clipboard', # easy clipboard access (copy & paste)
20
- 'guessmethod', # automatically correct typos (method_missing hook)
21
- # 'drx', # nice tk object inspector (.see) [not included because it fails to install out of the box on lots of systems]
22
- 'interactive_editor', # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
23
- 'coderay', # some nice colorful display ;)
24
- 'irb_rocket', # put result as comment instead of a new line!
25
- # 'zucker/all' # see rubyzucker.info
26
- ]
27
-
28
- if RubyVersion.is? 1.9
29
- irb_libs -= %w[guessmethod]
30
- end
31
-
32
- irb_libs.each{ |lib|
33
- begin
34
- require lib
35
-
36
- case lib
37
- when 'wirble'
38
- Wirble.init
39
- Wirble.colorize
40
-
41
- when 'hirb'
42
- Hirb::View.enable
43
-
44
- when 'fileutils'
45
- include FileUtils::Verbose
46
-
47
- when 'zucker/env'
48
- include OS # linux?, windows?, ...
49
- Zucker.more_aliases! # RV, RE
50
-
51
- when 'clipboard'
52
- # copies the clipboard
53
- def copy(str)
54
- Clipboard.copy(str)
55
- end
56
-
57
- # pastes the clipboard
58
- def paste
59
- Clipboard.paste
60
- end
61
-
62
- # copies everything you have entered in this irb session
63
- def copy_input
64
- copy session_history
65
- "The session input history has been copied to the clipboard."
66
- end
67
- alias copy_session_input copy_input
68
-
69
- # copies the output of all irb commands in this irb session
70
- def copy_output
71
- copy context.instance_variable_get(:@eval_history_values).inspect.gsub(/^\d+ (.*)/, '\1')
72
- "The session output history has been copied to the clipboard."
73
- end
74
- alias copy_session_output copy_output
75
-
76
- when 'coderay'
77
- # syntax highlight a string
78
- def colorize(string)
79
- puts CodeRay.scan( string, :ruby ).term
80
- end
81
-
82
- # syntax highlight a file
83
- def ray(path)
84
- puts CodeRay.scan( File.read(path), :ruby ).term
85
- end
86
-
87
- end
88
-
89
- rescue LoadError => err
90
- if err.to_s == 'irb_rocket' && RubyEngine.mri? && !OS.windows?
91
- warn "Couldn't load the irb_rocket gem. It is a great irb gem, but is not in the gem dependencies, because it is hosted on a different server\n --> You can install it with: gem install irb_rocket --source http://merbi.st"
92
- else
93
- warn "Couldn't load an irb library: #{err}"
94
- end
95
- end
96
- }
97
-
98
3
  # # # # #
99
- # shortcuts & helpers
100
-
101
- # shows the contents of your current directory (more such commands available by FileUtils)
102
- def ls(path='.')
103
- Dir[ File.join path, '*' ].map{|res| res =~ /^#{path}\/?/; $' }
104
- end
105
- alias dir ls
106
-
107
- # patch cd so that it also shows the current directory
108
- def cd(*args)
109
- FileUtils::Verbose.cd *args
110
- ls
111
- end
112
-
113
- # read file contents (also see ray for ruby source files ;) )
114
- def cat(path)
115
- File.read path
116
- end
117
-
118
- # allows concise syntax like rq:mathn
119
- def rq(lib)
120
- require lib.to_s
121
- end
122
-
123
- # returns the last lines, needed for some copy_ methods
124
- def session_history(number_of_lines = context.instance_variable_get(:@line_no) )
125
- Readline::HISTORY.entries[-number_of_lines...-1]*"\n"
126
- end
127
-
128
- # restart irb
129
- def reset! # restart irb
130
- exec$0
131
- end
132
-
133
- def ruby_version(which = nil)
134
- # test if installed
135
- unless `rvm -v` =~ /Seguin/
136
- raise 'Ruby Version Manager must be installed to use this command'
4
+ # require 'irbtools' in your .irbrc
5
+ # then call Irbtools.load or require 'irbtools/init' to load libraries
6
+ # see the README file for more information
7
+
8
+ require 'set'
9
+ require 'zucker/alias_for'
10
+ require 'zucker/env' # Info, OS, RubyVersion, RubyEngine
11
+
12
+ # suggested libraries
13
+ module Irbtools
14
+ @libs = Set['rubygems',
15
+ 'wirble', # colors
16
+ 'hirb', # active record tables
17
+ 'fileutils', # cd, pwd, ln_s, mv, rm, mkdir, touch ... ;)
18
+ 'zucker/debug', # nice debug printing (q, o, c, .m, .d)
19
+ 'ap', # nice debug printing (ap)
20
+ 'yaml', # nice debug printing (y)
21
+ 'g', # nice debug printing (g) - MacOS only :/
22
+ 'clipboard', # easy clipboard access (copy & paste)
23
+ 'guessmethod', # automatically correct typos (method_missing hook)
24
+ # 'drx', # nice tk object inspector (.see) [not included because it fails to install out of the box on lots of systems]
25
+ 'interactive_editor', # lets you open vim (or your favourite editor), hack something, save it, and it's loaded in the current irb session
26
+ 'coderay', # some nice colorful display ;)
27
+ 'irb_rocket', # put result as comment instead of a new line!
28
+ # 'zucker/all' # see rubyzucker.info
29
+ ]
30
+
31
+ if OS.windows?
32
+ @libs -= %w[irb_rocket coderay]
137
33
  end
138
34
 
139
- # show rubies if called without options
140
- if !which
141
- puts 'Availabe Rubies: ' +
142
- `rvm list`.scan( /^(?: |=>) (.*) \[/ )*", "
143
- return
35
+ unless OS.mac?
36
+ @libs -= %w[g]
144
37
  end
145
38
 
146
- # get irb suffix
147
- rv = `rvm use #{which}` # e.g. => "\ninfo: Using ruby 1.9.2 p0\n"
148
- # it does not change the ruby for the current user
149
- rv =~ /^.*Using(.*)\n/
150
-
151
- # if ruby is found, start it
152
- if $1
153
- ruby_name = File.split( $1 )[-1].tr(' ', '-')
154
- irbname = $0 + '-' + ruby_name + '@global'
155
- exec irbname
156
- else
157
- puts "Sorry, that Ruby version could not be found."
39
+ if RubyVersion.is? 1.9
40
+ @libs -= %w[guessmethod]
158
41
  end
159
- end
160
- alias use ruby_version
161
-
162
- # # # # #
163
- # irb options
164
- IRB.conf[:AUTO_INDENT] = true # simple auto indent
165
- IRB.conf[:EVAL_HISTORY] = 42424242424242424242 # creates the special __ variable
166
- IRB.conf[:SAVE_HISTORY] = 2000 # how many lines will go to ~/.irb_history
167
-
168
- # prompt
169
- IRB.conf[:PROMPT].merge!({:IRBTOOLS => {
170
- :PROMPT_I => ">> ", # normal
171
- :PROMPT_N => "| ", # indenting
172
- :PROMPT_C => "(>>) ", # continuing a statement
173
- :PROMPT_S => "%l> ", # continuing a string
174
- :RETURN => "=> %s \n",
175
- :AUTO_INDENT => true,
176
- }})
177
-
178
- IRB.conf[:PROMPT_MODE] = :IRBTOOLS
179
42
 
180
- # # # # #
181
- # workarounds
182
-
183
- # patch exec (irb_rocket bug)
184
- if IRB.const_defined? :CaptureIO
185
- module Kernel
186
- alias original_exec exec
187
- def exec(*args)
188
- STDOUT.reopen(IRB::CaptureIO.streams[:stdout])
189
- STDERR.reopen(IRB::CaptureIO.streams[:stderr])
190
- original_exec *args
43
+ class << self
44
+ def libs
45
+ @libs
191
46
  end
192
- end
193
-
194
- module IRB
195
- class CaptureIO
196
- def self.streams
197
- {
198
- :stdout => @@current_capture.instance_variable_get( :@out ),
199
- :stderr => @@current_capture.instance_variable_get( :@err ),
200
- }
201
- end
202
-
203
- alias original_capture capture
204
- def capture(&block)
205
- @@current_capture = self
206
- original_capture &block
207
- end
47
+ aliases_for :libs, :gems, :libraries
48
+
49
+ def load
50
+ require File.expand_path( 'irbtools/init', File.dirname(__FILE__) )
208
51
  end
209
52
  end
210
53
  end
211
54
 
212
- # # # # #
213
- # done :)
214
- puts "Welcome to IRB. You are using #{RUBY_DESCRIPTION}. Have fun ;)"
215
-
216
55
  # J-_-L
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irbtools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan Lelis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-05 00:00:00 +02:00
18
+ date: 2010-10-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency