File Shell
Comprehensive file system access tool. FileShell acts as a "virtual" shell prompt.
c = VirtualShell.new c.ls #=> ['ipso.txt']
- []
- cd
- chdir
- chmod
- chmod_R
- chown
- chown_R
- cp
- cp_r
- dryrun?
- fu
- install
- ln
- ln_s
- ln_sf
- ls
- mkdir
- mkdir_p
- move
- mv
- new
- pwd
- quiet?
- rm
- rm_r
- rm_rf
- rmdir
- root?
- touch
- verbose?
[R] | root |
[ show source ]
# 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
Direct access to a directory or a file.
[ show source ]
# 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
[ show source ]
# File lib/facets/fileshell.rb, line 78 def cd(dir, options=nil, &yld) fu(options).cd(dir, &yld) end
Alias for cd
chmod(mode, list, options)
[ show source ]
# File lib/facets/fileshell.rb, line 158 def chmod(mode, list, options=nil) fu(options).chmod(mode, list) end
chmod_R(mode, list, options)
[ show source ]
# 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)
[ show source ]
# 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)
[ show source ]
# File lib/facets/fileshell.rb, line 173 def chown_R(user, group, list, options=nil) fu(options).chown_R(user, group, list) end
[ show source ]
# File lib/facets/fileshell.rb, line 120 def cp(src, dest, options=nil) fu(options).cp(src, dest) end
[ show source ]
# File lib/facets/fileshell.rb, line 126 def cp_r(src, dest, options=nil) fu(options).cp_r(src, dest) end
[ show source ]
# File lib/facets/fileshell.rb, line 40 def dryrun? ; @dryrun ; end
install(src, dest, mode = <src‘s>, options)
[ show source ]
# File lib/facets/fileshell.rb, line 153 def install(src, dest, mode=src, options=nil) fu(options).install(src, dest, mode) end
[ show source ]
# File lib/facets/fileshell.rb, line 103 def ln(old, new, options=nil) fu(options).ln(old, new) end
[ show source ]
# 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)
[ show source ]
# File lib/facets/fileshell.rb, line 114 def ln_sf(src, dest, options=nil) fu(options).ln_sf(src, dest) end
Directory listing
[ show source ]
# 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
[ show source ]
# File lib/facets/fileshell.rb, line 85 def mkdir(dir, options=nil) fu(options).mkdir(dir) end
[ show source ]
# File lib/facets/fileshell.rb, line 91 def mkdir_p(dir, options=nil) fu(options).mkdir_p(dir) end
Alias for mv
[ show source ]
# File lib/facets/fileshell.rb, line 132 def mv(src, dest, options=nil) fu(options).mv(src, dest) end
Present working directory.
[ show source ]
# File lib/facets/fileshell.rb, line 65 def pwd; super; end
[ show source ]
# File lib/facets/fileshell.rb, line 41 def quiet? ; @quiet ; end
rm(list, options)
[ show source ]
# File lib/facets/fileshell.rb, line 138 def rm(list, options=nil) fu(options).rm(list) end
rm_r(list, options)
[ show source ]
# File lib/facets/fileshell.rb, line 143 def rm_r(list, options=nil) fu(options).rm_r(list) end
rm_rf(list, options)
[ show source ]
# File lib/facets/fileshell.rb, line 148 def rm_rf(list, options=nil) fu(options).rm_rf(list) end
[ show source ]
# File lib/facets/fileshell.rb, line 97 def rmdir(dir, options=nil) fu(options).rmdir(dir) end
Is a directory root?
[ show source ]
# 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)
[ show source ]
# File lib/facets/fileshell.rb, line 178 def touch(list, options=nil) fu(options).touch(list) end
[ show source ]
# File lib/facets/fileshell.rb, line 42 def verbose? ; !@quiet ; end
[ show source ]
# 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