File Shell

Comprehensive file system access tool. FileShell acts as a "virtual" shell prompt.

  c = VirtualShell.new
  c.ls  #=> ['ipso.txt']
Methods
Attributes
[R] root
Public Class methods
new(*root_and_options)
# File lib/facets/fileshell.rb, line 31
  def initialize(*root_and_options)
    @options = Hash === root_and_options ? root_and_options.pop : {}
    @root    = root_and_options.first || "/"

    @dryrun = options[:dryrun]
    @quiet  = options[:quiet]
    #@force  = options[:force]
  end
Public Instance methods
[](name)

Direct access to a directory or a file.

# File lib/facets/fileshell.rb, line 46
  def [](name)
    if File.directory?(name)
      Dir.new(name)
    elsif File.file?(name)
      File.new(name)
    else
      nil
    end
  end
cd(dir, options=nil, &yld)

Change directory.

cd(dir, options) cd(dir, options) {|dir| .… }

This method is also aliased as chdir
# File lib/facets/fileshell.rb, line 78
  def cd(dir, options=nil, &yld)
    fu(options).cd(dir, &yld)
  end
chdir(dir, options=nil, &yld)

Alias for cd

chmod(mode, list, options=nil)

chmod(mode, list, options)

# File lib/facets/fileshell.rb, line 158
  def chmod(mode, list, options=nil)
    fu(options).chmod(mode, list)
  end
chmod_R(mode, list, options=nil)

chmod_R(mode, list, options)

# File lib/facets/fileshell.rb, line 163
  def chmod_R(mode, list, options=nil)
    fu(options).chmod_R(mode, list)
  end
chown(user, group, list, options=nil)

chown(user, group, list, options)

# File lib/facets/fileshell.rb, line 168
  def chown(user, group, list, options=nil)
    fu(options).chown(user, group, list)
  end
chown_R(user, group, list, options=nil)

chown_R(user, group, list, options)

# File lib/facets/fileshell.rb, line 173
  def chown_R(user, group, list, options=nil)
    fu(options).chown_R(user, group, list)
  end
cp(src, dest, options=nil)

cp(src, dest, options) cp(list, dir, options)

# File lib/facets/fileshell.rb, line 120
  def cp(src, dest, options=nil)
    fu(options).cp(src, dest)
  end
cp_r(src, dest, options=nil)

cp_r(src, dest, options) cp_r(list, dir, options)

# File lib/facets/fileshell.rb, line 126
  def cp_r(src, dest, options=nil)
    fu(options).cp_r(src, dest)
  end
dryrun?()
# File lib/facets/fileshell.rb, line 40
  def dryrun? ; @dryrun ; end
install(src, dest, mode=src, options=nil)

install(src, dest, mode = <src‘s>, options)

# File lib/facets/fileshell.rb, line 153
  def install(src, dest, mode=src, options=nil)
    fu(options).install(src, dest, mode)
  end
ln(old, new, options=nil)

ln(old, new, options) ln(list, destdir, options)

# File lib/facets/fileshell.rb, line 103
  def ln(old, new, options=nil)
    fu(options).ln(old, new)
  end
ln_s(old, new, options=nil)

ln_s(old, new, options) ln_s(list, destdir, options)

# File lib/facets/fileshell.rb, line 109
  def ln_s(old, new, options=nil)
    fu(options).ln_s(old, new)
  end
ln_sf(src, dest, options=nil)

ln_sf(src, dest, options)

# File lib/facets/fileshell.rb, line 114
  def ln_sf(src, dest, options=nil)
    fu(options).ln_sf(src, dest)
  end
ls(dir, options=nil)

Directory listing

# File lib/facets/fileshell.rb, line 68
  def ls(dir, options=nil)
    Dir.entries.collect do |f|
      File.directory?(f) ? Dir.new(f) : File.new(f)
    end
  end
mkdir(dir, options=nil)

mkdir(dir, options) mkdir(list, options)

# File lib/facets/fileshell.rb, line 85
  def mkdir(dir, options=nil)
    fu(options).mkdir(dir)
  end
mkdir_p(dir, options=nil)

mkdir_p(dir, options) mkdir_p(list, options)

# File lib/facets/fileshell.rb, line 91
  def mkdir_p(dir, options=nil)
    fu(options).mkdir_p(dir)
  end
move(src, dest, options=nil)

Alias for mv

mv(src, dest, options=nil)

mv(src, dest, options) mv(list, dir, options)

This method is also aliased as move
# File lib/facets/fileshell.rb, line 132
  def mv(src, dest, options=nil)
    fu(options).mv(src, dest)
  end
pwd()

Present working directory.

# File lib/facets/fileshell.rb, line 65
  def pwd; super; end
quiet?()
# File lib/facets/fileshell.rb, line 41
  def quiet?  ; @quiet  ; end
rm(list, options=nil)

rm(list, options)

# File lib/facets/fileshell.rb, line 138
  def rm(list, options=nil)
    fu(options).rm(list)
  end
rm_r(list, options=nil)

rm_r(list, options)

# File lib/facets/fileshell.rb, line 143
  def rm_r(list, options=nil)
    fu(options).rm_r(list)
  end
rm_rf(list, options=nil)

rm_rf(list, options)

# File lib/facets/fileshell.rb, line 148
  def rm_rf(list, options=nil)
    fu(options).rm_rf(list)
  end
rmdir(dir, options=nil)

rmdir(dir, options) rmdir(list, options)

# File lib/facets/fileshell.rb, line 97
  def rmdir(dir, options=nil)
    fu(options).rmdir(dir)
  end
root?(dir=nil)

Is a directory root?

# File lib/facets/fileshell.rb, line 57
  def root?(dir=nil)
    pth = File.expand_path(dir||work)
    return true if pth == '/'
    return true if pth =~ /^(\w:)?\/$/
    false
  end
touch(list, options=nil)

touch(list, options)

# File lib/facets/fileshell.rb, line 178
  def touch(list, options=nil)
    fu(options).touch(list)
  end
verbose?()
# File lib/facets/fileshell.rb, line 42
  def verbose?  ; !@quiet  ; end
Private Instance methods
fu(opts)
# File lib/facets/fileshell.rb, line 185
  def fu(opts)
    nowrite = opts[:nowrite] || opts[:dryrun] || opts[:noop]   || dryrun?
    verbose = opts[:verbose] || opts[:dryrun] || !opts[:quiet] || verbose?

    if nowrite and verbose
      FileUtils::Dryrun
    elsif nowrite
      FileUtils::NoWrite
    elsif verbose
      FileUtils::Verbose
    else
      FileUtils
    end
  end