#!/usr/bin/env ruby
def tree entry=Dir.pwd, indent=0
entries = Dir.entries(entry)[2..-1]
entries.each do |item|
printable_item = entries.last != item ?
"├── #{File.basename(item)}" :
"└── #{File.basename(item)}"
puts "#{'│ ' * indent}#{printable_item}"
tree("#{entry}/#{item}", indent + 1) if File.directory?("#{entry}/#{item}")
end
end
ARGV.empty? ? tree : tree(ARGV.first)
#!/usr/bin/env ruby
# without the glyphs, if you prefer
def list entry=Dir.pwd
Dir.entries(entry)[2..-1].each do |item|
puts File.basename(item)
list("#{entry}/#{item}") if File.directory?("#{entry}/#{item}")
end
end
ARGV.empty? ? list : list(ARGV.first)