version.rb - shell version definition file
$Release Version: 0.6.0$
$Revision: 11708 $
$Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
—
| debug | -> | debug? |
| alias cascade? cascade | ||
| verbose | -> | verbose? |
| verbose | -> | verbose? |
| debug | -> | debug? |
| cwd | -> | dir |
| cwd | -> | getwd |
| cwd | -> | pwd |
| dir_stack | -> | dirs |
| cascade | [RW] | |
| command_processor | [R] | |
| cwd | [R] |
Dir related methods
Shell#cwd/dir/getwd/pwd Shell#chdir/cd Shell#pushdir/pushd Shell#popdir/popd Shell#mkdir Shell#rmdir |
| debug | [RW] | |
| debug | [RW] | |
| dir_stack | [R] | |
| process_controller | [R] | |
| record_separator | [RW] | |
| system_path | [R] | |
| umask | [RW] | |
| verbose | [RW] | |
| verbose | [RW] |
# File lib/shell.rb, line 223
223: def Shell.alias_command(ali, command, *opts, &block)
224: CommandProcessor.alias_command(ali, command, *opts, &block)
225: end
command definitions
# File lib/shell.rb, line 215
215: def Shell.def_system_command(command, path = command)
216: CommandProcessor.def_system_command(command, path)
217: end
# File lib/shell.rb, line 66
66: def default_record_separator
67: if @default_record_separator
68: @default_record_separator
69: else
70: $/
71: end
72: end
# File lib/shell.rb, line 74
74: def default_record_separator=(rs)
75: @default_record_separator = rs
76: end
# File lib/shell.rb, line 54
54: def default_system_path
55: if @default_system_path
56: @default_system_path
57: else
58: ENV["PATH"].split(":")
59: end
60: end
# File lib/shell.rb, line 62
62: def default_system_path=(path)
63: @default_system_path = path
64: end
# File lib/shell.rb, line 231
231: def Shell.install_system_commands(pre = "sys_")
232: CommandProcessor.install_system_commands(pre)
233: end
# File lib/shell.rb, line 79
79: def initialize
80: @cwd = Dir.pwd
81: @dir_stack = []
82: @umask = nil
83:
84: @system_path = Shell.default_system_path
85: @record_separator = Shell.default_record_separator
86:
87: @command_processor = CommandProcessor.new(self)
88: @process_controller = ProcessController.new(self)
89:
90: @verbose = Shell.verbose
91: @debug = Shell.debug
92: end
# File lib/shell.rb, line 244
244: def self.notify(*opts, &block)
245: Thread.exclusive do
246: if opts[-1].kind_of?(String)
247: yorn = verbose?
248: else
249: yorn = opts.pop
250: end
251: return unless yorn
252:
253: _head = true
254: print opts.collect{|mes|
255: mes = mes.dup
256: yield mes if iterator?
257: if _head
258: _head = false
259: "shell: " + mes
260: else
261: " " + mes
262: end
263: }.join("\n")+"\n"
264: end
265: end
# File lib/shell.rb, line 227
227: def Shell.unalias_command(ali)
228: CommandProcessor.unalias_command(ali)
229: end
# File lib/shell.rb, line 219
219: def Shell.undef_system_command(command)
220: CommandProcessor.undef_system_command(command)
221: end
If called as iterator, it restores the current directory when the block ends.
# File lib/shell.rb, line 144
144: def chdir(path = nil)
145: if iterator?
146: cwd_old = @cwd
147: begin
148: chdir(path)
149: yield
150: ensure
151: chdir(cwd_old)
152: end
153: else
154: path = "~" unless path
155: @cwd = expand_path(path)
156: notify "current dir: #{@cwd}"
157: rehash
158: self
159: end
160: end
# File lib/shell.rb, line 107
107: def debug=(val)
108: @debug = val
109: @verbose = val if val
110: end
# File lib/shell.rb, line 236
236: def inspect
237: if debug.kind_of?(Integer) && debug > 2
238: super
239: else
240: to_s
241: end
242: end
process management
# File lib/shell.rb, line 204
204: def jobs
205: @process_controller.jobs
206: end
# File lib/shell.rb, line 208
208: def kill(sig, command)
209: @process_controller.kill_job(sig, command)
210: end
# File lib/shell.rb, line 189
189: def popdir
190: if pop = @dir_stack.pop
191: chdir pop
192: notify "dir stack: [#{@dir_stack.join ', '}]"
193: self
194: else
195: Shell.Fail DirStackEmpty
196: end
197: end
# File lib/shell.rb, line 163
163: def pushdir(path = nil)
164: if iterator?
165: pushdir(path)
166: begin
167: yield
168: ensure
169: popdir
170: end
171: elsif path
172: @dir_stack.push @cwd
173: chdir path
174: notify "dir stack: [#{@dir_stack.join ', '}]"
175: self
176: else
177: if pop = @dir_stack.pop
178: @dir_stack.push @cwd
179: chdir pop
180: notify "dir stack: [#{@dir_stack.join ', '}]"
181: self
182: else
183: Shell.Fail DirStackEmpty
184: end
185: end
186: end