Class Shell
In: lib/shell/filter.rb
lib/shell/process-controller.rb
lib/shell/version.rb
lib/shell/command-processor.rb
lib/shell/builtin-command.rb
lib/shell/system-command.rb
lib/shell/error.rb
lib/shell.rb
Parent: Object
  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)

Methods

Included Modules

Error

Classes and Modules

Module Shell::Error
Class Shell::AppendFile
Class Shell::AppendIO
Class Shell::BuiltInCommand
Class Shell::Cat
Class Shell::CommandProcessor
Class Shell::Concat
Class Shell::Echo
Class Shell::Filter
Class Shell::Glob
Class Shell::ProcessController
Class Shell::SystemCommand
Class Shell::Tee

External Aliases

debug -> debug?
  alias cascade? cascade
verbose -> verbose?
verbose -> verbose?
debug -> debug?
cwd -> dir
cwd -> getwd
cwd -> pwd
dir_stack -> dirs

Attributes

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] 

Public Class methods

[Source]

     # 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

[Source]

    # File lib/shell.rb, line 48
48:     def cd(path)
49:       sh = new
50:       sh.cd path
51:       sh
52:     end

[Source]

    # File lib/shell.rb, line 43
43:     def debug=(val)
44:       @debug = val
45:       @verbose = val if val
46:     end

command definitions

[Source]

     # File lib/shell.rb, line 215
215:   def Shell.def_system_command(command, path = command)
216:     CommandProcessor.def_system_command(command, path)
217:   end

[Source]

    # 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

[Source]

    # File lib/shell.rb, line 74
74:     def default_record_separator=(rs)
75:       @default_record_separator = rs
76:     end

[Source]

    # 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

[Source]

    # File lib/shell.rb, line 62
62:     def default_system_path=(path)
63:       @default_system_path = path
64:     end

[Source]

     # File lib/shell.rb, line 231
231:   def Shell.install_system_commands(pre = "sys_")
232:     CommandProcessor.install_system_commands(pre)
233:   end

[Source]

    # 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

[Source]

     # 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

[Source]

     # File lib/shell.rb, line 227
227:   def Shell.unalias_command(ali)
228:     CommandProcessor.unalias_command(ali)
229:   end

[Source]

     # File lib/shell.rb, line 219
219:   def Shell.undef_system_command(command)
220:     CommandProcessor.undef_system_command(command)
221:   end

Public Instance methods

cd(path = nil)

Alias for chdir

If called as iterator, it restores the current directory when the block ends.

[Source]

     # 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

[Source]

     # File lib/shell.rb, line 107
107:   def debug=(val)
108:     @debug = val
109:     @verbose = val if val
110:   end

[Source]

     # File lib/shell.rb, line 118
118:   def expand_path(path)
119:     File.expand_path(path, @cwd)
120:   end

[Source]

     # 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

[Source]

     # File lib/shell.rb, line 204
204:   def jobs
205:     @process_controller.jobs
206:   end

[Source]

     # File lib/shell.rb, line 208
208:   def kill(sig, command)
209:     @process_controller.kill_job(sig, command)
210:   end
popd()

Alias for popdir

[Source]

     # 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
pushd(path = nil)

Alias for pushdir

[Source]

     # 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

[Source]

    # File lib/shell.rb, line 96
96:   def system_path=(path)
97:     @system_path = path
98:     rehash
99:   end

[Validate]