Path  Path::Shell

Parent

  • Object
Generated with Razzle Dazzle Redfish

[Validate]

Shell Prompt class

Ratch Shell object provides a limited file system shell in code. It is similar to having a shell prompt available to you in Ruby.

Public Class Methods

[](path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 742
    def self.[](path)
      new(path)
    end
new(*path_opts) click to toggle source

New Shell object.

# File lib/path/shell.rb, line 23
    def initialize(*path_opts)
      opts = (Hash===path_opts.last ? path_opts.pop : {})
      path = path_opts

      @quiet   = opts[:quiet]
      @noop    = opts[:noop]
      @verbose = opts[:verbose]
      @debug   = opts[:debug]

      if path.empty?
        path = Dir.pwd
      else
        path = File.join(*path)
      end

      raise FileNotFound, "#{path}" unless ::File.exist?(path)
      raise FileNotFound, "#{path}" unless ::File.directory?(path)

      @work  = dir(path)
    end
require_minitar() click to toggle source

(Not documented)

# File lib/path/shell/tar.rb, line 10
    def self.require_minitar
      require 'zlib'
      begin
        require 'archive/tar/minitar'
      rescue LoadError
        require 'path/minitar'
      end
    end

Public Instance Methods

/(path) click to toggle source

Join paths. TODO: Should this return a new directory object? Or should it change directories?

# File lib/path/shell.rb, line 210
    def /(path)
      #@work += dir   # did not work, why?
      @work = dir(localize(path))
      self
    end
==(other) click to toggle source
# File lib/path/shell.rb, line 79
    def ==(other)
      return false unless self.class===other
      return true  if     @work == other.work
      false
    end
[](name) click to toggle source

Get the FileObject for the given file name.

# File lib/path/shell.rb, line 119
    def [](name)
      #FileObject[localize(name)]
      #Pathname.new(localize(path))
      Pathlist.new(localize(path))
    end
absolute?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 327
    def absolute?(path)   ; FileTest.absolute?(path)       ; end
amass(include_globs, exclude_globs=[], ignore_globs=[]) click to toggle source

An intergrated glob like method that takes a set of include globs, exclude globs and ignore globs to produce a collection of paths.

Ignore_globs differ from exclude_globs in that they match by the basename of the path rather than the whole pathname.

# File lib/path/shell.rb, line 526
    def amass(include_globs, exclude_globs=[], ignore_globs=[])
      locally do
        fileutils.amass(include_globs, exclude_globs, ignore_globs)
      end
    end
append(path, text) click to toggle source

Append to file.

# File lib/path/shell.rb, line 292
    def append(path, text)
      puts "append #{path}" if verbose?
      File.open(localize(path), 'a'){ |f| f << text } unless noop?
    end
blockdev?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 315
    def blockdev?(path)   ; FileTest.blockdev?(localize(path))  ; end
cache(path) click to toggle source

Look up a cache file.

# File lib/path/shell/xdg.rb, line 22
    def cache(path)
      file(XDG.xdg_cache_file(path))
    end
cd(path, &block) click to toggle source

Change working directory.

TODO: Make thread safe.

# File lib/path/shell.rb, line 259
    def cd(path, &block)
      if block
        work_old = @work
        begin
          @work = dir(localize(path))
          locally(&block)
          #mutex.synchronize do
          #  Dir.chdir(@work){ block.call }
          #end
        ensure
          @work = work_old
        end
      else
        @work = dir(localize(path))
      end
    end
Also aliased as: chdir
chardev?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 308
    def chardev?(path)    ; FileTest.chardev?(localize(path))   ; end
chdir(path, &block) click to toggle source

Alias for cd

chmod(mode, list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 481
    def chmod(mode, list, options={})
      list = localize(list)
      fileutils.chmod(mode, list, options)
    end
chmod_r(mode, list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 486
    def chmod_r(mode, list, options={})
      list = localize(list)
      fileutils.chmod_r(mode, list, options)
    end
chown(user, group, list, options={}) click to toggle source

alias_method :chmod_R, :chmod_r

# File lib/path/shell.rb, line 492
    def chown(user, group, list, options={})
      list = localize(list)
      fileutils.chown(user, group, list, options)
    end
chown_r(user, group, list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 497
    def chown_r(user, group, list, options={})
      list = localize(list)
      fileutils.chown_r(user, group, list, options)
    end
cmp(a,b) click to toggle source

Same as identical?

# File lib/path/shell.rb, line 388
    def cmp(a,b)
      fileutils.compare_file(a,b)
    end
compare_file(path, other) click to toggle source

Alias for identical?

config(path) click to toggle source

Look up a config file.

# File lib/path/shell/xdg.rb, line 12
    def config(path)
      file(XDG.xdg_config_file(path))
    end
copy(src, dest, options={}) click to toggle source

Alias for cp

cp(src, dest, options={}) click to toggle source

cp(list, dir, options={})

# File lib/path/shell.rb, line 432
    def cp(src, dest, options={})
      src  = localize(src)
      dest = localize(dest)
      fileutils.cp(src, dest, options)
    end
Also aliased as: copy
cp_r(src, dest, options={}) click to toggle source

cp_r(list, dir, options={})

# File lib/path/shell.rb, line 440
    def cp_r(src, dest, options={})
      src  = localize(src)
      dest = localize(dest)
      fileutils.cp_r(src, dest, options)
    end
data(path) click to toggle source

Look up a data file.

# File lib/path/shell/xdg.rb, line 17
    def data(path)
      file(XDG.xdg_data_file(path))
    end
debug?() click to toggle source

(Not documented)

# File lib/path/shell.rb, line 67
    def debug?   ; @debug   ; end
dir(path) click to toggle source

def doc(name)

  Document.new(name)

end

# File lib/path/shell.rb, line 136
    def dir(path)
      #Directory.new(name)
      raise unless File.directory?(path)
      Pathname.new(localize(path))
    end
directories() click to toggle source

Returns list of documents.

# File lib/path/shell.rb, line 170
    def directories ; work.directories ; end
directory?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 305
    def directory?(path)  ; FileTest.directory?(localize(path)) ; end
directory_entries() click to toggle source

Lists directory entries.

# File lib/path/shell.rb, line 154
    def directory_entries
      work.entries.select{ |d| d.directory? }
    end
dryrun?() click to toggle source

(Not documented)

# File lib/path/shell.rb, line 72
    def dryrun?  ; @noop  && @verbose ; end
entries() click to toggle source

Lists all entries.

# File lib/path/shell.rb, line 148
    def entries
      work.entries
    end
Also aliased as: ls
executable?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 322
    def executable?(path) ; FileTest.executable?(localize(path))  ; end
executable_real?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 330
    def executable_real?(path) ; FileTest.executable_real?(localize(path)) ; end
exist?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 309
    def exist?(path)      ; FileTest.exist?(localize(path))     ; end
exists?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 310
    def exists?(path)     ; FileTest.exists?(localize(path))    ; end
file(path) click to toggle source

should file and this be the same?

# File lib/path/shell.rb, line 126
    def file(path)
      #FileObject[name]
      raise unless File.file?(path)
      Pathname.new(localize(path))
    end
file?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 313
    def file?(path)       ; FileTest.file?(localize(path))      ; end
file_entries() click to toggle source

Lists directory entries.

# File lib/path/shell.rb, line 159
    def file_entries
      work.entries.select{ |f| f.file? }
    end
files( dir, copy ) click to toggle source

Put together the list of files to copy.

# File lib/path/shell/ftp.rb, line 78
    def files( dir, copy )
      Dir.chdir(dir) do
        del, add = copy.partition{ |f| /^[-]/ =~ f }

        # remove - and + prefixes
        del.collect!{ |f| f.sub(/^[-]/,'') }
        add.collect!{ |f| f.sub(/^[+]/,'') }

        #del.concat(must_exclude)

        files = []
        add.each{ |g| files += Dir.glob(g) }
        del.each{ |g| files -= Dir.glob(g) }

        files.collect!{ |f| f.sub(/^\//,'') }

        return files
      end
    end
ftp( keys ) click to toggle source

Use ftp to upload files.

# File lib/path/shell/ftp.rb, line 7
    def ftp( keys )
      keys = upload_parameters(keys)

      # set transfer rules
      if keys.stage
        trans = stage_transfer(keys.stage)
      else
        files(keys.dir, keys.copy).each do |from|
          trans << [from,from]
        end
      end

      # append location of publication dir to from
      dir = keys.dir
      trans.collect!{ |from,to| [File.join(dir,from), to] }

      if keys.dryrun
        puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
        keys.trans.each do |f, t|
          puts "ftp put #{f} #{t}"
        end
      else
        require 'net/ftp'
        Net::FTP.open(keys.host) do |ftp|
          ftp.login(keys.user) #password?
          ftp.chdir(keys.root)
          keys.trans.each do |f, t|
            puts "ftp #{f} #{t}" unless keys.quiet
            ftp.putbinaryfile( f, t, 1024 )
          end
        end
      end
    end
glob(*patterns, &block) click to toggle source

Glob pattern. Returns matches as strings.

# File lib/path/shell.rb, line 173
    def glob(*patterns, &block)
      opts = (::Integer===patterns.last ? patterns.pop : 0)
      matches = []
      locally do
        matches = patterns.map{ |pattern| ::Dir.glob(pattern, opts) }.flatten
      end
      if block_given?
        matches.each(&block)
      else
        matches
      end
    end
grpowned?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 316
    def grpowned?(path)   ; FileTest.grpowned?(localize(path))  ; end
gzip(file, tofile=nil, options={}) click to toggle source

Create a gzip file.

# File lib/path/shell/gzip.rb, line 7
    def gzip(file, tofile=nil, options={})
      require 'zlib'

      noop, verbose = *util_options(options)

      tofile ||= File.basename(file) + '.gz'

      puts "gzip #{file}" if verbose

      file   = localize(file)
      tofile = localize(tofile)

      Zlib::GzipWriter.open(tofile) do |gz|
        gz.write(File.read(file))
      end unless noop

      return tofile
    end
home(*args) click to toggle source

Current home path.

# File lib/path/shell.rb, line 96
    def home(*args)
      dir('~', *args)
    end
home_cache() click to toggle source

Return the home cache directory.

# File lib/path/shell/xdg.rb, line 47
    def home_cache
      dir(XDG.xdg_cache_home)
    end
home_config() click to toggle source

Return the home config directory.

# File lib/path/shell/xdg.rb, line 37
    def home_config
      dir(XDG.xdg_config_home)
    end
home_data() click to toggle source

Return the home data directory.

# File lib/path/shell/xdg.rb, line 42
    def home_data
      dir(XDG.xdg_data_home)
    end
identical?(path, other) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 333
    def identical?(path, other)
      FileTest.identical?(localize(path), localize(other))
    end
Also aliased as: compare_file
install(src, dest, mode, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 475
    def install(src, dest, mode, options={})
      src  = localize(src)
      dest = localize(dest)
      fileutils.install(src, dest, mode, options)
    end
ln(old, new, options={}) click to toggle source

ln(list, destdir, options={})

# File lib/path/shell.rb, line 410
    def ln(old, new, options={})
      old = localize(old)
      new = localize(new)
      fileutils.ln(old, new, options)
    end
Also aliased as: link
ln_s(old, new, options={}) click to toggle source

ln_s(list, destdir, options={})

# File lib/path/shell.rb, line 418
    def ln_s(old, new, options={})
      old = localize(old)
      new = localize(new)
      fileutils.ln_s(old, new, options)
    end
Also aliased as: symlink
ln_sf(old, new, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 425
    def ln_sf(old, new, options={})
      old = localize(old)
      new = localize(new)
      fileutils.ln_sf(old, new, options)
    end
localize(local_path) click to toggle source

Returns a path local to the current working path.

# File lib/path/shell.rb, line 670
    def localize(local_path)
      # some path arguments are optional
      return local_path unless local_path
      #
      case local_path
      when Array
        local_path.collect do |lp|
          if absolute?(lp)
            lp
          else
            File.expand_path(File.join(work.to_s, lp))
          end
        end
      else
        # do not localize an absolute path
        return local_path if absolute?(local_path)
        File.expand_path(File.join(work.to_s, local_path))
      end
    end
locally(&block) click to toggle source
# File lib/path/shell.rb, line 691
    def locally(&block)
      if work.to_s == Dir.pwd
        block.call
      else
        mutex.synchronize do
          #work.chdir(&block)
          Dir.chdir(work, &block)
        end
      end
    end
ls() click to toggle source

Alias for entries

match(*patterns, &block) click to toggle source

Match pattern. Like glob but returns file objects.

# File lib/path/shell.rb, line 196
    def match(*patterns, &block)
      opts = (::Integer===patterns.last ? patterns.pop : 0)
      patterns = localize(patterns)
      matches  = patterns.map{ |pattern| ::Dir.glob(pattern, opts) }.flatten
      matches  = matches.map{ |f| FileObject[f] }
      if block_given?
        matches.each(&block)
      else
        matches
      end
    end
mkdir(dir, options={}) click to toggle source
# File lib/path/shell.rb, line 393
    def mkdir(dir, options={})
      dir = localize(dir)
      fileutils.mkdir(dir, options)
    end
mkdir_p(dir, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 398
    def mkdir_p(dir, options={})
      dir = localize(dir)
      fileutils.mkdir_p(dir, options)
    end
Also aliased as: mkpath
mkpath(dir, options={}) click to toggle source

Alias for mkdir_p

move(src, dest, options={}) click to toggle source

Alias for mv

multiglob(*a) click to toggle source

TODO: Ultimately merge glob and multiglob.

# File lib/path/shell.rb, line 187
    def multiglob(*a)
      Dir.multiglob(*a)
    end
multiglob_r(*a) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 191
    def multiglob_r(*a)
      Dir.multiglob_r(*a)
    end
mutex() click to toggle source
# File lib/path/shell.rb, line 45
    def mutex
      @mutex ||= Mutex.new
    end
mv(src, dest, options={}) click to toggle source

mv(list, dir, options={})

# File lib/path/shell.rb, line 447
    def mv(src, dest, options={})
      src  = localize(src)
      dest = localize(dest)
      fileutils.mv(src, dest, options)
    end
Also aliased as: move
noop?() click to toggle source

(Not documented)

# File lib/path/shell.rb, line 69
    def noop?    ; @noop    ; end
outofdate?(path, *sources) click to toggle source
# File lib/path/shell.rb, line 533
    def outofdate?(path, *sources)
      #fileutils.outofdate?(localize(path), localize(sources))  # DIDN'T WORK, why?
      locally do
        fileutils.outofdate?(path, sources.flatten)
      end
    end
owned?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 320
    def owned?(path)      ; FileTest.owned?(localize(path))     ; end
parent() click to toggle source
 Return a new prompt with the same location.
 NOTE: Use #dup or #clone ?

def new ; Shell.new(work) ; end

# File lib/path/shell.rb, line 113
    def parent
      dir('..')
    end
path(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 142
    def path(path)
      Pathname.new(localize(path))
    end
Also aliased as: pathname
pathname(path) click to toggle source

Alias for path

pipe?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 312
    def pipe?(path)       ; FileTest.pipe?(localize(path))      ; end
pwd(*args) click to toggle source

Alias for work

pwd() click to toggle source

Present working directory.

# File lib/path/shell.rb, line 383
    def pwd
      work.to_s
    end
quiet?() click to toggle source
 Opertaton mode. This can be :noop, :verbose or :dryrun.
 The later is the same as the first two combined.

def mode(opts=nil)

  return @mode unless opts
  opts.each do |key, val|
    next unless val
    case key
    when :noop
      @mode = (@mode == :verbose ? :dryrun : :noop)
    when :verbose
      @mode = (@mode == :noop ? :dryrun : :verbose)
    when :dryrun
      @mode = :dryrun
    end
  end

end

# File lib/path/shell.rb, line 66
    def quiet?   ; @quiet   ; end
read(path) click to toggle source

Read file.

# File lib/path/shell.rb, line 281
    def read(path)
      File.read(localize(path))
    end
readable?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 307
    def readable?(path)   ; FileTest.readable?(localize(path))  ; end
readable_real?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 331
    def readable_real?(path)   ; FileTest.readable_real?(localize(path))   ; end
relative?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 326
    def relative?(path)   ; FileTest.relative?(path)       ; end
remove(list, options={}) click to toggle source

Alias for rm

rm(list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 454
    def rm(list, options={})
      list = localize(list)
      fileutils.rm(list, options)
    end
Also aliased as: remove
rm_f(list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 465
    def rm_f(list, options={})
      list = localize(list)
      fileutils.rm_f(list, options)
    end
rm_r(list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 460
    def rm_r(list, options={})
      list = localize(list)
      fileutils.rm_r(list, options)
    end
rm_rf(list, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 470
    def rm_rf(list, options={})
      list = localize(list)
      fileutils.rm_rf(list, options)
    end
rmdir(dir, options={}) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 404
    def rmdir(dir, options={})
      dir = localize(dir)
      fileutils.rmdir(dir, options)
    end
root(*args) click to toggle source

Root location.

# File lib/path/shell.rb, line 91
    def root(*args)
      dir('/', *args)
    end
root_config() click to toggle source

Return a enumertor of system config directories.

# File lib/path/shell/xdg.rb, line 27
    def root_config() #_directories
      XDG.xdg_config_dirs.to_enum(:each){ |f| dir(f) }
    end
root_data() click to toggle source

Return a enumertor of system data directories.

# File lib/path/shell/xdg.rb, line 32
    def root_data() #_directories
      XDG.xdg_data_dirs.to_enum(:each){ |f| dir(f) }
    end
safe?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 324
    def safe?(path)       ; FileTest.safe?(localize(path)) ; end
setgid?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 317
    def setgid?(path)     ; FileTest.setgid?(localize(path))    ; end
setuid?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 318
    def setuid?(path)     ; FileTest.setuid?(localize(path))    ; end
sftp( keys ) click to toggle source

Use sftp to upload files.

# File lib/path/shell/ftp.rb, line 43
    def sftp( keys )
      keys = upload_parameters(keys)

      # set transfer rules
      if keys.stage
        trans = stage_transfer(keys.stage)
      else
        files(keys.dir, keys.copy).each do |from|
          trans << [from,from]
        end
      end

      # append location of publication dir to from
      dir = keys.dir
      trans.collect!{ |from,to| [File.join(dir,from), to] }

      if keys.dryrun
        puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
        keys.trans.each do |f,t|
          puts "sftp put #{f} #{t}"
        end
      else
        require 'net/sftp'
        Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
          #sftp.login( user )
          sftp.chdir(keys.root)
          keys.trans.each do |f,t|
            puts "sftp #{f} #{t}" unless keys.quiet
            sftp.put_file(f,t) #, 1024 )
          end
        end
      end
    end
sh(cmd) click to toggle source

Shell runner.

# File lib/path/shell.rb, line 227
    def sh(cmd)
      #puts "--> system call: #{cmd}" if verbose?
      puts cmd if verbose?
      return true if noop?
      #locally do
        if quiet?
          silently{ system(cmd) }
        else
          system(cmd)
        end
      #end
    end
size(path) click to toggle source
# File lib/path/shell.rb, line 303
    def size(path)        ; FileTest.size(localize(path))       ; end
size?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 304
    def size?(path)       ; FileTest.size?(localize(path))      ; end
socket?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 319
    def socket?(path)     ; FileTest.socket?(localize(path))    ; end
stage(stage_dir, files) click to toggle source

TODO: should this have SOURCE diectory?

  stage(directory, source_dir, files)
# File lib/path/shell.rb, line 512
    def stage(stage_dir, files)
      #dir   = localize(directory)
      #files = localize(files)
      locally do
        fileutils.stage(stage_dir, work, files)
      end
    end
stage_transfer( list ) click to toggle source

Combine three part stage list into a two part from->to list.

Using the stage list of three space separated fields.

  fromdir file todir

This is used to generate a from -> to list of the form:

 fromdir/file todir/file
# File lib/path/shell/ftp.rb, line 108
    def stage_transfer( list )
      trans = []
      list.each do |line|
        trans << Shellwords.shellwords(line)
      end

      trans.collect! do |from, base, to|
        file = File.join(from,base)
        to = File.join(to,base)
        [from, to]
      end
    end
sticky?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 314
    def sticky?(path)     ; FileTest.sticky?(localize(path))    ; end
system(cmd) click to toggle source
# File lib/path/shell.rb, line 220
    def system(cmd)
      locally do
        super(cmd)
      end
    end
tar(folder, file=nil, options={}) click to toggle source

Tar

# File lib/path/shell/tar.rb, line 21
    def tar(folder, file=nil, options={})
      Shell.require_minitar
      noop, verbose = *util_options(options)
      file ||= File.basename(File.expand_path(folder)) + '.tar'
      cmd = "tar -cf #{file} #{folder}"
      puts cmd if verbose
      unless noop
        locally do
          gzIO = File.open(file, 'wb')
          Archive::Tar::Minitar.pack(folder, gzIO)
        end
      end
      path(file)
    end
tar_gzip(folder, file=nil, options={}) click to toggle source

Tar Gzip

# File lib/path/shell/tar.rb, line 55
    def tar_gzip(folder, file=nil, options={})
      Shell.require_minitar
      noop, verbose = *util_options(options)
      file ||= File.basename(File.expand_path(folder)) + '.tar.gz' # '.tgz' which ?
      cmd = "tar --gzip -czf #{file} #{folder}"
      puts cmd if verbose
      unless noop
        locally do #folder, file = localize(folder), localize(file)
          gzIO = Zlib::GzipWriter.new(File.open(file, 'wb'))
          Archive::Tar::Minitar.pack(folder, gzIO)
        end
      end
      path(file)
    end
Also aliased as: tar_z
tar_z(folder, file=nil, options={}) click to toggle source

Alias for tar_gzip

to_s() click to toggle source

String representation is work directory path.

# File lib/path/shell.rb, line 76
    def to_s ; work.to_s ; end
touch(list, options={}) click to toggle source

alias_method :chown_R, :chown_r

# File lib/path/shell.rb, line 503
    def touch(list, options={})
      list = localize(list)
      fileutils.touch(list, options)
    end
trace?() click to toggle source

(Not documented)

# File lib/path/shell.rb, line 73
    def trace?   ; @debug && @verbose ; end
ungzip(file, options={}) click to toggle source

Unpack a gzip file.

# File lib/path/shell/gzip.rb, line 28
    def ungzip(file, options={})
      require 'zlib'

      noop, verbose = *util_options(options)

      fname = File.basename(file).chomp(File.extname(file))

      puts "ungzip #{file}" if verbose

      fname = localize(fname)
      file  = localize(file)

      Zlib::GzipReader.open(file) do |gz|
        File.open(fname, 'wb'){ |f| f << gz.read }
      end unless noop

      return fname
    end
untar(file, options={}) click to toggle source

Untar

# File lib/path/shell/tar.rb, line 38
    def untar(file, options={})
      Shell.require_minitar
      noop, verbose = *util_options(options)
      #file ||= File.basename(File.expand_path(folder)) + '.tar'
      cmd = "untar #{file}"
      puts cmd if verbose
      unless noop
        locally do
          gzIO = File.open(file, 'wb')
          Archive::Tar::Minitar.unpack(gzIO)
        end
      end
      path(file)
    end
untar_gzip(file, options={}) click to toggle source

Untar Gzip

FIXME: Write unified untar_gzip function.

# File lib/path/shell/tar.rb, line 75
    def untar_gzip(file, options={})
      Shell.require_minitar
      untar(ungzip(file, options), options)
    end
Also aliased as: untar_z
untar_z(file, options={}) click to toggle source

Alias for untar_gzip

unzip(file, options={}) click to toggle source

Unzip

# File lib/path/shell/zip.rb, line 31
    def unzip(file, options={})
      noop, verbose = *util_options(options)

      file = localize(file)

      cmd = "unzip #{file}"
      puts   cmd if verbose
      system cmd if !noop
    end
uptodate?(path, *sources) click to toggle source
# File lib/path/shell.rb, line 541
    def uptodate?(path, *sources)
      locally do
        fileutils.uptodate?(path, sources.flatten)
      end
    end
verbose?() click to toggle source

(Not documented)

# File lib/path/shell.rb, line 70
    def verbose? ; @verbose ; end
work(*args) click to toggle source

Current working path.

# File lib/path/shell.rb, line 101
    def work(*args)
      return @work if args.empty?
      return dir(@work, *args)
    end
Also aliased as: pwd
work_cache() click to toggle source

Return the work cache directory.

# File lib/path/shell/xdg.rb, line 57
    def work_cache
      dir(XDG.xdg_cache_work)
    end
work_config() click to toggle source

Return the work config directory.

# File lib/path/shell/xdg.rb, line 52
    def work_config
      dir(XDG.xdg_config_work)
    end
writable?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 321
    def writable?(path)   ; FileTest.writable?(localize(path))  ; end
writable_real?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 329
    def writable_real?(path)   ; FileTest.writable_real?(localize(path))   ; end
write(path, text) click to toggle source

Write file.

# File lib/path/shell.rb, line 286
    def write(path, text)
      puts "write #{path}" if verbose?
      File.open(localize(path), 'w'){ |f| f << text } unless noop?
    end
zero?(path) click to toggle source

(Not documented)

# File lib/path/shell.rb, line 311
    def zero?(path)       ; FileTest.zero?(localize(path))      ; end
zip(folder, file=nil, options={}) click to toggle source

Zip

TODO: replace with a pure ruby zip library

# File lib/path/shell/zip.rb, line 12
    def zip(folder, file=nil, options={})
      noop, verbose = *util_options(options)

      raise ArgumentError if folder == '.*'

      file ||= File.basename(File.expand_path(folder)) + '.zip'

      folder = localize(folder)
      file   = localize(file)

      cmd = "zip -rqu #{file} #{folder}"
      puts   cmd if verbose
      system cmd if !noop

      return file
    end

Private Instance Methods

fileutils() click to toggle source

Returns FileUtils module based on mode.

# File lib/path/shell.rb, line 705
    def fileutils
      if dryrun?
        ::FileUtils::DryRun
      elsif noop?
        ::FileUtils::Noop
      elsif verbose?
        ::FileUtils::Verbose
      else
        ::FileUtils
      end
    end
util_options(options) click to toggle source

This may be used by script commands to allow for per command noop and verbose options. Global options have precedence.

# File lib/path/shell.rb, line 734
    def util_options(options)
      noop    = noop?    || options[:noop]    || options[:dryrun]
      verbose = verbose? || options[:verbose] || options[:dryrun]
      return noop, verbose
    end

Disabled; run with --debug to generate this.