Skip to content

Instantly share code, notes, and snippets.

@audibleblink
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save audibleblink/9d0a2629f72286d1674d to your computer and use it in GitHub Desktop.
Save audibleblink/9d0a2629f72286d1674d to your computer and use it in GitHub Desktop.
reimplemented unix tree
#!/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)
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment