-- shell.rb $Release Version: 0.6.0 $ $Revision$ $Date$ by Keiju ISHITSUKA(keiju@ishitsuka.com) =begin = ��Ū ruby���sh/csh�Τ褦�˥��ޥ�ɤμ¹Եڤӥե��륿��󥰤��ڤ˹Ԥ�. sh/csh������ʸ��ruby�ε�ǽ���Ѥ��Ƽ¸�����. = ��ʥ��饹���� == Shell Shell���֥������Ȥϥ����ȥǥ��쥯�ȥ�����, ���ޥ�ɼ¹ԤϤ�������� ���Хѥ��ˤʤ�ޤ�. --- Shell#cwd --- Shell#dir --- Shell#getwd --- Shell#pwd �����ȥǥ��쥯�ȥ���֤��� --- Shell#system_path ���ޥ�ɥ������ѥ���������֤��� --- Shell#umask umask���֤��� == Filter ���ޥ�ɤμ¹Է�̤Ϥ��٤�Filter�Ȥ��Ƥ�����ޤ�. Enumerable��include�� �Ƥ��ޤ�. = ��ʥ᥽�åɰ��� == ���ޥ����� OS��Υ��ޥ�ɤ�¹Ԥ���ˤϤޤ�, Shell�Υ᥽�åɤȤ���������ޤ�. ��) ���ޥ�ɤ�������ʤ��Ȥ�ľ�ܼ¹ԤǤ���Shell#system���ޥ�ɤ⤢��ޤ�. --- Shell.def_system_command(command, path = command) Shell�Υ᥽�åɤȤ���command����Ͽ���ޤ�. ��) Shell.def_system_command "ls" ls ����� Shell.def_system_command "sys_sort", "sort" sort���ޥ�ɤ�sys_sort�Ȥ������ --- Shell.undef_system_command(command) command�������ޤ�. --- Shell.alias_command(ali, command, *opts) {...} command��alias�򤷤ޤ�. ��) Shell.alias_command "lsC", "ls", "-CBF", "--show-control-chars" Shell.alias_command("lsC", "ls"){|*opts| ["-CBF", "--show-control-chars", *opts]} --- Shell.unalias_command(ali) command��alias�������ޤ�. --- Shell.install_system_commands(pre = "sys_") system_path��ˤ������Ƥμ¹Բ�ǽ�ե������Shell���������. �᥽�� ��̾�ϸ��Υե�����̾��Ƭ��pre��Ĥ�����ΤȤʤ�. == ���� --- Shell.new �ץ������Υ����ȥǥ��쥯�ȥ�򥫥��ȥǥ��쥯�ȥ�Ȥ���Shell�� �֥������Ȥ��������ޤ�. --- Shell.cd(path) path�򥫥��ȥǥ��쥯�ȥ�Ȥ���Shell���֥������Ȥ��������ޤ�. == �ץ��������� --- Shell#jobs �������塼��󥰤���Ƥ���job�ΰ������֤�. --- Shell#kill sig, job job�˥����ʥ�sig������ == �����ȥǥ��쥯�ȥ���� --- Shell#cd(path, &block) --- Shell#chdir �����ȥǥ��쥯�ȥ��path�ˤ���. ���ƥ졼���Ȥ��ƸƤФ줿�Ȥ��ˤ� �֥��å��¹���Τߥ����ȥǥ��쥯�ȥ���ѹ�����. --- Shell#pushd(path = nil, &block) --- Shell#pushdir �����ȥǥ��쥯�ȥ��ǥ��쥯�ȥꥹ���å��ˤĤ�, �����ȥǥ��쥯 �ȥ��path�ˤ���. path����ά���줿�Ȥ��ˤ�, �����ȥǥ��쥯�ȥ�� �ǥ��쥯�ȥꥹ���å��Υȥåפ�򴹤���. ���ƥ졼���Ȥ��ƸƤФ줿�� ���ˤ�, �֥��å��¹���Τ�pushd����. --- Shell#popd --- Shell#popdir �ǥ��쥯�ȥꥹ���å�����ݥåפ�, ����򥫥��ȥǥ��쥯�ȥ�ˤ���. == �ե�����/�ǥ��쥯�ȥ���� --- Shell#foreach(path = nil, &block) path���ե�����ʤ�, File#foreach path���ǥ��쥯�ȥ�ʤ�, Dir#foreach --- Shell#open(path, mode) path���ե�����ʤ�, File#open path���ǥ��쥯�ȥ�ʤ�, Dir#open --- Shell#unlink(path) path���ե�����ʤ�, File#unlink path���ǥ��쥯�ȥ�ʤ�, Dir#unlink --- Shell#test(command, file1, file2) --- Shell#[command, file1, file2] �ե�����ƥ��ȴؿ�test��Ʊ��. ��) sh[?e, "foo"] sh[:e, "foo"] sh["e", "foo"] sh[:exists?, "foo"] sh["exists?", "foo"] --- Shell#mkdir(*path) Dir.mkdir��Ʊ��(ʣ����) --- Shell#rmdir(*path) Dir.rmdir��Ʊ��(ʣ����) == ���ޥ�ɼ¹� --- System#system(command, *opts) command��¹Ԥ���. ��) print sh.system("ls", "-l") sh.system("ls", "-l") | sh.head > STDOUT --- System#rehash ��ϥå��夹�� --- Shell#transact &block �֥��å���Ǥ�shell��self�Ȥ��Ƽ¹Ԥ���. ��) sh.transact{system("ls", "-l") | head > STDOUT} --- Shell#out(dev = STDOUT, &block) transact��ƤӽФ����η�̤�dev�˽��Ϥ���. == �������ޥ�� --- Shell#echo(*strings) --- Shell#cat(*files) --- Shell#glob(patten) --- Shell#tee(file) �����ϼ¹Ԥ����, ���������ƤȤ���Filter���֥������Ȥ��֤��ޤ�. --- Filter#each &block �ե��륿�ΰ�Ԥ��Ĥ�block���Ϥ�. --- Filter#<(src) src��ե��륿�����ϤȤ���. src��, ʸ����ʤ�Хե������, IO�Ǥ��� �Ф���򤽤Τޤ����ϤȤ���. --- Filter#>(to) src��ե��륿�ν��ϤȤ���. to��, ʸ����ʤ�Хե������, IO�Ǥ��� �Ф���򤽤Τޤ޽��ϤȤ���. --- Filter#>>(to) src��ե��륿���ɲä���. to��, ʸ����ʤ�Хե������, IO�Ǥ���� ����򤽤Τޤ޽��ϤȤ���. --- Filter#|(filter) �ѥ��׷�� --- Filter#+(filter) filter1 + filter2 �� filter1�ν��Ϥθ�, filter2�ν��Ϥ�Ԥ�. --- Filter#to_a --- Filter#to_s == �ȹ��ߥ��ޥ�� --- Shell#atime(file) --- Shell#basename(file, *opt) --- Shell#chmod(mode, *files) --- Shell#chown(owner, group, *file) --- Shell#ctime(file) --- Shell#delete(*file) --- Shell#dirname(file) --- Shell#ftype(file) --- Shell#join(*file) --- Shell#link(file_from, file_to) --- Shell#lstat(file) --- Shell#mtime(file) --- Shell#readlink(file) --- Shell#rename(file_from, file_to) --- Shell#split(file) --- Shell#stat(file) --- Shell#symlink(file_from, file_to) --- Shell#truncate(file, length) --- Shell#utime(atime, mtime, *file) ������File���饹�ˤ���Ʊ̾�Υ��饹�᥽�åɤ�Ʊ���Ǥ�. --- Shell#blockdev?(file) --- Shell#chardev?(file) --- Shell#directory?(file) --- Shell#executable?(file) --- Shell#executable_real?(file) --- Shell#exist?(file)/Shell#exists?(file) --- Shell#file?(file) --- Shell#grpowned?(file) --- Shell#owned?(file) --- Shell#pipe?(file) --- Shell#readable?(file) --- Shell#readable_real?(file) --- Shell#setgid?(file) --- Shell#setuid?(file) --- Shell#size(file)/Shell#size?(file) --- Shell#socket?(file) --- Shell#sticky?(file) --- Shell#symlink?(file) --- Shell#writable?(file) --- Shell#writable_real?(file) --- Shell#zero?(file) ������FileTest���饹�ˤ���Ʊ̾�Υ��饹�᥽�åɤ�Ʊ���Ǥ�. --- Shell#syscopy(filename_from, filename_to) --- Shell#copy(filename_from, filename_to) --- Shell#move(filename_from, filename_to) --- Shell#compare(filename_from, filename_to) --- Shell#safe_unlink(*filenames) --- Shell#makedirs(*filenames) --- Shell#install(filename_from, filename_to, mode) ������FileTools���饹�ˤ���Ʊ̾�Υ��饹�᥽�åɤ�Ʊ���Ǥ�. ����¾, �ʲ��Τ�Τ������ꥢ������Ƥ��ޤ�. --- Shell#cmp <- Shell#compare --- Shell#mv <- Shell#move --- Shell#cp <- Shell#copy --- Shell#rm_f <- Shell#safe_unlink --- Shell#mkpath <- Shell#makedirs = ����ץ� == ex1 sh = Shell.cd("/tmp") sh.mkdir "shell-test-1" unless sh.exists?("shell-test-1") sh.cd("shell-test-1") for dir in ["dir1", "dir3", "dir5"] if !sh.exists?(dir) sh.mkdir dir sh.cd(dir) do f = sh.open("tmpFile", "w") f.print "TEST\n" f.close end print sh.pwd end end == ex2 sh = Shell.cd("/tmp") sh.transact do mkdir "shell-test-1" unless exists?("shell-test-1") cd("shell-test-1") for dir in ["dir1", "dir3", "dir5"] if !exists?(dir) mkdir dir cd(dir) do f = open("tmpFile", "w") f.print "TEST\n" f.close end print pwd end end end == ex3 sh.cat("/etc/printcap") | sh.tee("tee1") > "tee2" (sh.cat < "/etc/printcap") | sh.tee("tee11") > "tee12" sh.cat("/etc/printcap") | sh.tee("tee1") >> "tee2" (sh.cat < "/etc/printcap") | sh.tee("tee11") >> "tee12" == ex4 print sh.cat("/etc/passwd").head.collect{|l| l =~ /keiju/} =end