Made a working one with only ruby and git as a dependency:
One liner to type in irb
:
def format(file); split = file.split('/'); return file unless split.size > 1; "│ " * (split.size - 2) + "└── " + split.last; end; def list(dir, start: true); puts dir if start; `git ls-tree master "#{dir}" --name-only`.split("\n").sort.each { |line| split = line.split('/'); puts format(line); list(line + '/', start: false) if File.directory?(line) }; end; list('.')
And as a more proper script:
#!/usr/bin/env ruby
def format(file)
split = file.split('/')
return file unless split.size > 1
"│ " * (split.size - 2) + "└── " + split.last
end
def list(dir, start: true)
puts dir if start
`git ls-tree master "#{dir}" --name-only`.split("\n").sort.each do |line|
split = line.split('/')
puts format(line)
list(line + '/', start: false) if File.directory?(line)
end
end
list(ARGV.first || '.')
Name it gittree
then chmod +x gittree
and then ./gittree
or ./gittree app/
for instance.
- This only works if the current directory is the same as the script's current directory
- This could potentially execute arbitrary commands passed as parameter
- It's far from fool proof :D Might make it better if people ask, for now it scratch my inch and I don't have to trust somebody's code with < 100 downloads a month