2 $Release Version: 0.6.0 $
4 by Keiju ISHITSUKA(keiju@ishitsuka.com)
10 It realizes a wish to do execution of commands with filters and pipes
11 like sh/csh by using just native facilities of ruby.
17 Every shell object has its own current working directory, and executes
18 each command as if it stands in the directory.
25 Returns the current directory
29 Returns the command search path in an array
37 Any result of command exection is a Filter. Filter include
38 Enumerable, therefore a Filter object can use all Enumerable
43 == Command definitions
45 In order to execute a command on your OS, you need to define it as a
48 Alternatively, you can execute any command via Shell#system even if it
51 --- Shell.def_system_command(command, path = command)
53 Defines a command. Registers <path> as a Shell method
57 Shell.def_system_command "ls"
60 Shell.def_system_command "sys_sort", "sort"
61 Defines sys_sort as sort.
63 --- Shell.undef_system_command(command)
67 --- Shell.alias_command(ali, command, *opts) {...}
72 Shell.alias_command "lsC", "ls", "-CBF", "--show-control-chars"
73 Shell.alias_command("lsC", "ls"){|*opts| ["-CBF", "--show-control-chars", *opts]}
75 --- Shell.unalias_command(ali)
79 --- Shell.install_system_commands(pre = "sys_")
81 Defines all commands in the default_system_path as Shell method,
82 all with <pre> prefixed to their names.
88 Creates a Shell object which current directory is set to the
89 process current directory.
93 Creates a Shell object which current directory is set to
100 Returns a list of scheduled jobs.
102 --- Shell#kill sig, job
104 Sends a signal <sig> to <job>.
106 == Current directory operations
108 --- Shell#cd(path, &block)
111 Changes the current directory to <path>. If a block is given,
112 it restores the current directory when the block ends.
114 --- Shell#pushd(path = nil, &block)
117 Pushes the current directory to the directory stack, changing
118 the current directory to <path>. If <path> is omitted, it
119 exchanges its current directory and the top of its directory
120 stack. If a block is given, it restores the current directory
126 Pops a directory from the directory stack, and sets the current
129 == File and directory operations
131 --- Shell#foreach(path = nil, &block)
134 File#foreach (when path is a file)
135 Dir#foreach (when path is a directory)
137 --- Shell#open(path, mode)
140 File#open (when path is a file)
141 Dir#open (when path is a directory)
143 --- Shell#unlink(path)
146 Dir#open (when path is a file)
147 Dir#unlink (when path is a directory)
149 --- Shell#test(command, file1, file2)
150 --- Shell#[command, file1, file2]
160 --- Shell#mkdir(*path)
162 Same as Dir.mkdir (with multiple directories allowed)
164 --- Shell#rmdir(*path)
166 Same as Dir.rmdir (with multiple directories allowed)
170 --- System#system(command, *opts)
172 Executes <command> with <opts>.
175 print sh.system("ls", "-l")
176 sh.system("ls", "-l") | sh.head > STDOUT
182 --- Shell#transact &block
184 Executes a block as self.
186 sh.transact{system("ls", "-l") | head > STDOUT}
188 --- Shell#out(dev = STDOUT, &block)
190 Does transact, with redirecting the result output to <dev>.
194 --- Shell#echo(*strings)
195 --- Shell#cat(*files)
196 --- Shell#glob(patten)
199 Return Filter objects, which are results of their execution.
201 --- Filter#each &block
203 Iterates a block for each line of it.
207 Inputs from <src>, which is either a string of a file name or an
212 Outputs to <to>, which is either a string of a file name or an
217 Appends the ouput to <to>, which is either a string of a file
222 Processes a pipeline.
226 (filter1 + filter2) outputs filter1, and then outputs filter2.
233 --- Shell#atime(file)
234 --- Shell#basename(file, *opt)
235 --- Shell#chmod(mode, *files)
236 --- Shell#chown(owner, group, *file)
237 --- Shell#ctime(file)
238 --- Shell#delete(*file)
239 --- Shell#dirname(file)
240 --- Shell#ftype(file)
241 --- Shell#join(*file)
242 --- Shell#link(file_from, file_to)
243 --- Shell#lstat(file)
244 --- Shell#mtime(file)
245 --- Shell#readlink(file)
246 --- Shell#rename(file_from, file_to)
247 --- Shell#split(file)
249 --- Shell#symlink(file_from, file_to)
250 --- Shell#truncate(file, length)
251 --- Shell#utime(atime, mtime, *file)
253 Equivalent to the class methods of File with the same names.
255 --- Shell#blockdev?(file)
256 --- Shell#chardev?(file)
257 --- Shell#directory?(file)
258 --- Shell#executable?(file)
259 --- Shell#executable_real?(file)
260 --- Shell#exist?(file)/Shell#exists?(file)
261 --- Shell#file?(file)
262 --- Shell#grpowned?(file)
263 --- Shell#owned?(file)
264 --- Shell#pipe?(file)
265 --- Shell#readable?(file)
266 --- Shell#readable_real?(file)
267 --- Shell#setgid?(file)
268 --- Shell#setuid?(file)
269 --- Shell#size(file)/Shell#size?(file)
270 --- Shell#socket?(file)
271 --- Shell#sticky?(file)
272 --- Shell#symlink?(file)
273 --- Shell#writable?(file)
274 --- Shell#writable_real?(file)
275 --- Shell#zero?(file)
277 Equivalent to the class methods of FileTest with the same names.
279 --- Shell#syscopy(filename_from, filename_to)
280 --- Shell#copy(filename_from, filename_to)
281 --- Shell#move(filename_from, filename_to)
282 --- Shell#compare(filename_from, filename_to)
283 --- Shell#safe_unlink(*filenames)
284 --- Shell#makedirs(*filenames)
285 --- Shell#install(filename_from, filename_to, mode)
287 Equivalent to the class methods of FileTools with the same
290 And also, there are some aliases for convenience:
292 --- Shell#cmp <- Shell#compare
293 --- Shell#mv <- Shell#move
294 --- Shell#cp <- Shell#copy
295 --- Shell#rm_f <- Shell#safe_unlink
296 --- Shell#mkpath <- Shell#makedirs
302 sh = Shell.cd("/tmp")
303 sh.mkdir "shell-test-1" unless sh.exists?("shell-test-1")
304 sh.cd("shell-test-1")
305 for dir in ["dir1", "dir3", "dir5"]
309 f = sh.open("tmpFile", "w")
319 sh = Shell.cd("/tmp")
321 mkdir "shell-test-1" unless exists?("shell-test-1")
323 for dir in ["dir1", "dir3", "dir5"]
327 f = open("tmpFile", "w")
338 sh.cat("/etc/printcap") | sh.tee("tee1") > "tee2"
339 (sh.cat < "/etc/printcap") | sh.tee("tee11") > "tee12"
340 sh.cat("/etc/printcap") | sh.tee("tee1") >> "tee2"
341 (sh.cat < "/etc/printcap") | sh.tee("tee11") >> "tee12"
345 print sh.cat("/etc/passwd").head.collect{|l| l =~ /keiju/}