Top Level Namespace
Defined Under Namespace
Modules: Redwood
Instance Method Summary collapse
-
#optparse ⇒ Object
Redwood is an implementation of ‘tree` in Ruby.
- #setup_tree(tree, options) ⇒ Object
- #statement(tree) ⇒ Object
- #usage ⇒ Object
Instance Method Details
#optparse ⇒ Object
Redwood is an implementation of ‘tree` in Ruby
Usage: redwood [ OPTIONS ] [ DIRECTORY ]
Learn more about the original at: mama.indstate.edu/users/ice/tree/
11 |
# File 'bin/redwood', line 11 require 'optparse' |
#setup_tree(tree, options) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'bin/redwood', line 68 def setup_tree(tree, ) if [:depth] abort 'Invalid level, must be greater than 0' if [:depth] <= 1 tree.descendants.each {|f| f.unlink if f.depth > [:depth] } end if ![:follow_symlinks] tree.descendants.each do |f| if f.symlink? f.value << " -> #{f.readlink}" end f.unlink if f.parent.symlink? end end if [:only_directories] tree.descendants.each {|f| f.unlink if !f.directory? } end if ![:show_hidden_files] tree.descendants.each do |f| f.unlink if f.basename.index('.').eql?(0) end end tree.walk {|f| f.value = f.path } if [:full_path] if [:date] tree.descendants.each {|f| f.value.insert(0,"[#{f.send([:date]).strftime('%b %d %H:%M')}] ") } end if [:size] tree.descendants.each {|f| f.value.insert(0,"[#{f.size}] ") if f.size? } end if [:ftype] tree.descendants.each do |f| f.value << "|" if f.ftype == 'fifo' if f.symlink? f.value << "@" elsif f.directory? f.value << "/" end f.value << "*" if f.executable? && f.file? f.value << "=" if f.socket? end end tree end |
#statement(tree) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'bin/redwood', line 53 def statement(tree) directories = 0 files = 0 tree.descendants.each do |f| if f.directory? directories += 1 else files += 1 end end d = directories.eql?(1) ? 'directory' : 'directories' f = files.eql?(1) ? 'file' : 'files' "#{directories} #{d}, #{files} #{f}" end |
#usage ⇒ Object
13 14 15 16 17 18 |
# File 'bin/redwood', line 13 def usage File.readlines(__FILE__). grep(/^##.*/). map { |line| line.chomp[3..-1] }. join("\n") end |