Class: Shell
- Inherits:
-
Object
- Object
- Shell
- Extended by:
- Exception2MessageMapper
- Includes:
- Error
- Defined in:
- lib/shell/filter.rb,
lib/shell.rb,
lib/shell/error.rb,
lib/shell/version.rb,
lib/shell/system-command.rb,
lib/shell/builtin-command.rb,
lib/shell/command-processor.rb,
lib/shell/process-controller.rb
Overview
version.rb - shell version definition file
$Release Version: 0.6.0$
$Revision$
$Date$
by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
–
Defined Under Namespace
Modules: Error Classes: AppendFile, AppendIO, BuiltInCommand, Cat, CommandProcessor, Concat, Echo, Filter, Glob, ProcessController, SystemCommand, Tee
Class Attribute Summary collapse
-
.cascade ⇒ Object
Returns the value of attribute cascade.
-
.debug ⇒ Object
(also: debug?)
Returns the value of attribute debug.
-
.verbose ⇒ Object
(also: verbose?)
Returns the value of attribute verbose.
Instance Attribute Summary collapse
-
#command_processor ⇒ Object
readonly
Returns the value of attribute command_processor.
-
#cwd ⇒ Object
(also: #dir, #getwd, #pwd)
readonly
Dir related methods.
-
#debug ⇒ Object
(also: #debug?)
Returns the value of attribute debug.
-
#dir_stack ⇒ Object
(also: #dirs)
readonly
Returns the value of attribute dir_stack.
-
#process_controller ⇒ Object
readonly
Returns the value of attribute process_controller.
-
#record_separator ⇒ Object
Returns the value of attribute record_separator.
-
#system_path ⇒ Object
Returns the value of attribute system_path.
-
#umask ⇒ Object
Returns the value of attribute umask.
-
#verbose ⇒ Object
(also: #verbose?)
Returns the value of attribute verbose.
Class Method Summary collapse
- .alias_command(ali, command, *opts, &block) ⇒ Object
- .cd(path) ⇒ Object
-
.def_system_command(command, path = command) ⇒ Object
command definitions.
- .default_record_separator ⇒ Object
- .default_record_separator=(rs) ⇒ Object
- .default_system_path ⇒ Object
- .default_system_path=(path) ⇒ Object
- .install_system_commands(pre = "sys_") ⇒ Object
- .notify(*opts, &block) ⇒ Object
- .unalias_command(ali) ⇒ Object
- .undef_system_command(command) ⇒ Object
Instance Method Summary collapse
-
#chdir(path = nil) ⇒ Object
(also: #cd)
If called as iterator, it restores the current directory when the block ends.
- #expand_path(path) ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #inspect ⇒ Object
-
#jobs ⇒ Object
process management.
- #kill(sig, command) ⇒ Object
- #popdir ⇒ Object (also: #popd)
- #pushdir(path = nil) ⇒ Object (also: #pushd)
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/shell.rb', line 79 def initialize @cwd = Dir.pwd @dir_stack = [] @umask = nil @system_path = Shell.default_system_path @record_separator = Shell.default_record_separator @command_processor = CommandProcessor.new(self) @process_controller = ProcessController.new(self) @verbose = Shell.verbose @debug = Shell.debug end |
Class Attribute Details
.cascade ⇒ Object
Returns the value of attribute cascade.
34 35 36 |
# File 'lib/shell.rb', line 34 def cascade @cascade end |
.debug ⇒ Object Also known as: debug?
Returns the value of attribute debug.
35 36 37 |
# File 'lib/shell.rb', line 35 def debug @debug end |
.verbose ⇒ Object Also known as: verbose?
Returns the value of attribute verbose.
36 37 38 |
# File 'lib/shell.rb', line 36 def verbose @verbose end |
Instance Attribute Details
#command_processor ⇒ Object (readonly)
Returns the value of attribute command_processor.
115 116 117 |
# File 'lib/shell.rb', line 115 def command_processor @command_processor end |
#cwd ⇒ Object (readonly) Also known as: dir, getwd, pwd
Dir related methods
Shell#cwd/dir/getwd/pwd Shell#chdir/cd Shell#pushdir/pushd Shell#popdir/popd Shell#mkdir Shell#rmdir
134 135 136 |
# File 'lib/shell.rb', line 134 def cwd @cwd end |
#debug ⇒ Object Also known as: debug?
Returns the value of attribute debug.
105 106 107 |
# File 'lib/shell.rb', line 105 def debug @debug end |
#dir_stack ⇒ Object (readonly) Also known as: dirs
Returns the value of attribute dir_stack.
139 140 141 |
# File 'lib/shell.rb', line 139 def dir_stack @dir_stack end |
#process_controller ⇒ Object (readonly)
Returns the value of attribute process_controller.
116 117 118 |
# File 'lib/shell.rb', line 116 def process_controller @process_controller end |
#record_separator ⇒ Object
Returns the value of attribute record_separator.
102 103 104 |
# File 'lib/shell.rb', line 102 def record_separator @record_separator end |
#system_path ⇒ Object
Returns the value of attribute system_path.
94 95 96 |
# File 'lib/shell.rb', line 94 def system_path @system_path end |
#umask ⇒ Object
Returns the value of attribute umask.
101 102 103 |
# File 'lib/shell.rb', line 101 def umask @umask end |
#verbose ⇒ Object Also known as: verbose?
Returns the value of attribute verbose.
104 105 106 |
# File 'lib/shell.rb', line 104 def verbose @verbose end |
Class Method Details
.alias_command(ali, command, *opts, &block) ⇒ Object
223 224 225 |
# File 'lib/shell.rb', line 223 def Shell.alias_command(ali, command, *opts, &block) CommandProcessor.alias_command(ali, command, *opts, &block) end |
.cd(path) ⇒ Object
48 49 50 51 52 |
# File 'lib/shell.rb', line 48 def cd(path) sh = new sh.cd path sh end |
.def_system_command(command, path = command) ⇒ Object
command definitions
215 216 217 |
# File 'lib/shell.rb', line 215 def Shell.def_system_command(command, path = command) CommandProcessor.def_system_command(command, path) end |
.default_record_separator ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/shell.rb', line 66 def default_record_separator if @default_record_separator @default_record_separator else $/ end end |
.default_record_separator=(rs) ⇒ Object
74 75 76 |
# File 'lib/shell.rb', line 74 def default_record_separator=(rs) @default_record_separator = rs end |
.default_system_path ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/shell.rb', line 54 def default_system_path if @default_system_path @default_system_path else ENV["PATH"].split(":") end end |
.default_system_path=(path) ⇒ Object
62 63 64 |
# File 'lib/shell.rb', line 62 def default_system_path=(path) @default_system_path = path end |
.install_system_commands(pre = "sys_") ⇒ Object
231 232 233 |
# File 'lib/shell.rb', line 231 def Shell.install_system_commands(pre = "sys_") CommandProcessor.install_system_commands(pre) end |
.notify(*opts, &block) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/shell.rb', line 244 def self.notify(*opts, &block) Thread.exclusive do if opts[-1].kind_of?(String) yorn = verbose? else yorn = opts.pop end return unless yorn _head = true print opts.collect{|mes| mes = mes.dup yield mes if iterator? if _head _head = false "shell: " + mes else " " + mes end }.join("\n")+"\n" end end |
.unalias_command(ali) ⇒ Object
227 228 229 |
# File 'lib/shell.rb', line 227 def Shell.unalias_command(ali) CommandProcessor.unalias_command(ali) end |
.undef_system_command(command) ⇒ Object
219 220 221 |
# File 'lib/shell.rb', line 219 def Shell.undef_system_command(command) CommandProcessor.undef_system_command(command) end |
Instance Method Details
#chdir(path = nil) ⇒ Object Also known as: cd
If called as iterator, it restores the current directory when the block ends.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/shell.rb', line 144 def chdir(path = nil) if iterator? cwd_old = @cwd begin chdir(path) yield ensure chdir(cwd_old) end else path = "~" unless path @cwd = (path) notify "current dir: #{@cwd}" rehash self end end |
#expand_path(path) ⇒ Object
118 119 120 |
# File 'lib/shell.rb', line 118 def (path) File.(path, @cwd) end |
#inspect ⇒ Object
236 237 238 239 240 241 242 |
# File 'lib/shell.rb', line 236 def inspect if debug.kind_of?(Integer) && debug > 2 super else to_s end end |
#jobs ⇒ Object
process management
204 205 206 |
# File 'lib/shell.rb', line 204 def jobs @process_controller.jobs end |
#kill(sig, command) ⇒ Object
208 209 210 |
# File 'lib/shell.rb', line 208 def kill(sig, command) @process_controller.kill_job(sig, command) end |
#popdir ⇒ Object Also known as: popd
189 190 191 192 193 194 195 196 197 |
# File 'lib/shell.rb', line 189 def popdir if pop = @dir_stack.pop chdir pop notify "dir stack: [#{@dir_stack.join ', '}]" self else Shell.Fail DirStackEmpty end end |
#pushdir(path = nil) ⇒ Object Also known as: pushd
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/shell.rb', line 163 def pushdir(path = nil) if iterator? pushdir(path) begin yield ensure popdir end elsif path @dir_stack.push @cwd chdir path notify "dir stack: [#{@dir_stack.join ', '}]" self else if pop = @dir_stack.pop @dir_stack.push @cwd chdir pop notify "dir stack: [#{@dir_stack.join ', '}]" self else Shell.Fail DirStackEmpty end end end |