summaryrefslogtreecommitdiff
path: root/lib/shell.rb
diff options
context:
space:
mode:
-rw-r--r--lib/shell.rb115
1 files changed, 76 insertions, 39 deletions
@@ -1,9 +1,9 @@
#
# shell.rb -
-# $Release Version: 0.6.0 $
-# $Revision: 1.8 $
-# $Date: 2001/03/19 09:01:11 $
-# by Keiju ISHITSUKA(Nippon Rational Inc.)
#
# --
#
@@ -11,14 +11,17 @@
#
require "e2mmap"
-require "thread"
require "shell/error"
require "shell/command-processor"
require "shell/process-controller"
class Shell
- @RCS_ID='-$Id: shell.rb,v 1.8 2001/03/19 09:01:11 keiju Exp keiju $-'
include Error
extend Exception2MessageMapper
@@ -30,7 +33,13 @@ class Shell
@debug = false
@verbose = true
class << Shell
attr_accessor :cascade, :debug, :verbose
# alias cascade? cascade
@@ -44,9 +53,7 @@ class Shell
end
def cd(path)
- sh = new
- sh.cd path
- sh
end
def default_system_path
@@ -72,12 +79,19 @@ class Shell
def default_record_separator=(rs)
@default_record_separator = rs
end
end
- def initialize
- @cwd = Dir.pwd
@dir_stack = []
- @umask = nil
@system_path = Shell.default_system_path
@record_separator = Shell.default_record_separator
@@ -126,49 +140,58 @@ class Shell
# Shell#mkdir
# Shell#rmdir
- attr :cwd
alias dir cwd
alias getwd cwd
alias pwd cwd
- attr :dir_stack
alias dirs dir_stack
# If called as iterator, it restores the current directory when the
# block ends.
- def chdir(path = nil)
if iterator?
cwd_old = @cwd
begin
- chdir(path)
yield
ensure
- chdir(cwd_old)
end
else
path = "~" unless path
@cwd = expand_path(path)
notify "current dir: #{@cwd}"
rehash
- self
end
end
alias cd chdir
- 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
@@ -178,10 +201,14 @@ class Shell
Shell.Fail DirStackEmpty
end
end
end
alias pushd pushdir
def popdir
if pop = @dir_stack.pop
chdir pop
notify "dir stack: [#{@dir_stack.join ', '}]"
@@ -189,10 +216,10 @@ class Shell
else
Shell.Fail DirStackEmpty
end
end
alias popd popdir
-
#
# process management
#
@@ -237,25 +264,35 @@ class Shell
end
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