dirtree 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +45 -11
- data/dirtree.gemspec +1 -0
- data/exe/dirtree +33 -6
- data/lib/dirtree/version.rb +1 -1
- data/templates/circles.html.erb +111 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb64f8d686c8126e4dab42c711d7f3b17eb050d3
|
4
|
+
data.tar.gz: ff74a6c7a5e016e8e5852421916fb62190c7c24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67ed70759e896f00a666d5568b0e7d793081f6e85fecb7bf61e6eff1e33ce9a0f0f984f1aaacacda46147caa457c6be2a80939630a73af18db6662908020878d
|
7
|
+
data.tar.gz: a41b0d579446826b277b709c4f538c4486db68f33cdb59b54510e2ca523543bdeb0132903104e46b968284991121d5a579ffbb5a3e036c9b747ef207bdc49c7d
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
# Dirtree
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/dirtree.svg)](https://badge.fury.io/rb/dirtree)
|
4
|
+
|
3
5
|
Dirtree visualizes an list of file paths into a tree graph, printed as HTML page, it can be useful in visualizing a whole project you're working on to start cleanup or organizing your code or spotting large directories or unneeded files.
|
4
6
|
|
7
|
+
## Tree template
|
8
|
+
![http://i.imgur.com/cGhx0lG.png](http://i.imgur.com/cGhx0lG.png)
|
9
|
+
|
10
|
+
## Circles template
|
11
|
+
![http://i.imgur.com/WvfOgCp.png](http://i.imgur.com/WvfOgCp.png)
|
12
|
+
|
5
13
|
## Installation
|
6
14
|
|
7
15
|
|
@@ -15,28 +23,54 @@ Dirtree visualizes an list of file paths into a tree graph, printed as HTML page
|
|
15
23
|
-o, --output=File.html Specify a path to write output, if not specified output will be printed to STDOUT
|
16
24
|
|
17
25
|
|
18
|
-
|
26
|
+
## Examples
|
27
|
+
|
28
|
+
**Visualize current directory recursively**
|
29
|
+
|
30
|
+
```
|
31
|
+
$ dirtree -o output.html **/* *
|
32
|
+
```
|
33
|
+
|
34
|
+
make sure you have `globstar` on
|
35
|
+
```
|
36
|
+
$ shopt -s globstar
|
37
|
+
```
|
38
|
+
|
39
|
+
**Visualize files from git ls**
|
40
|
+
|
41
|
+
```
|
42
|
+
$ git ls-files | dirtree -o output.html
|
43
|
+
```
|
19
44
|
|
20
|
-
|
45
|
+
**Dirtree prints to standard output if no --output option specified so you can redirect it**
|
21
46
|
|
22
|
-
|
47
|
+
```
|
48
|
+
$ git ls-files | dirtree > output.html
|
49
|
+
```
|
23
50
|
|
24
|
-
|
51
|
+
**visualize only files that include specific word**
|
25
52
|
|
26
|
-
|
53
|
+
```
|
54
|
+
$ git ls-files | grep keyword | dirtree > output.html
|
55
|
+
```
|
27
56
|
|
28
|
-
|
57
|
+
**works with find**
|
29
58
|
|
30
|
-
|
59
|
+
visualize all files that ends with `rb`
|
31
60
|
|
32
|
-
|
61
|
+
```
|
62
|
+
$ find ~ -name *rb | dirtree > output.html
|
63
|
+
```
|
33
64
|
|
34
|
-
|
65
|
+
**With ag:silver searcher**
|
35
66
|
|
36
|
-
|
67
|
+
```
|
68
|
+
$ ag -l | dirtree -o output.html
|
69
|
+
```
|
37
70
|
|
38
|
-
|
71
|
+
## Conjunctions
|
39
72
|
|
73
|
+
* [lsgh](https://www.github.com/blazeeboy/lsgh) Draw a tree for a github user/org and open pull requests.
|
40
74
|
|
41
75
|
## Contributing
|
42
76
|
|
data/dirtree.gemspec
CHANGED
data/exe/dirtree
CHANGED
@@ -4,23 +4,51 @@ require 'optparse'
|
|
4
4
|
require 'json'
|
5
5
|
require 'erb'
|
6
6
|
|
7
|
-
|
7
|
+
templates_dir = File.join(File.dirname(__FILE__), '..', 'templates')
|
8
|
+
templates = Dir.open(templates_dir).map do |file|
|
9
|
+
file[0...file.index('.')]
|
10
|
+
end.reject(&:empty?)
|
11
|
+
|
12
|
+
options = {
|
13
|
+
template: 'tree'
|
14
|
+
}
|
15
|
+
|
8
16
|
OptionParser.new do |opts|
|
9
17
|
opts.banner = 'Usage: dirtree [options]... [file]...'
|
10
18
|
|
11
|
-
opts.on(
|
19
|
+
opts.on(
|
20
|
+
'-v',
|
21
|
+
'--version',
|
22
|
+
'Print version'
|
23
|
+
) do
|
12
24
|
puts "Dirtree version #{Dirtree::VERSION}"
|
13
25
|
exit
|
14
26
|
end
|
15
27
|
|
16
|
-
opts.on(
|
28
|
+
opts.on(
|
29
|
+
'-h',
|
30
|
+
'--help',
|
31
|
+
'Show this help text'
|
32
|
+
) do
|
17
33
|
puts opts
|
18
34
|
exit
|
19
35
|
end
|
20
36
|
|
21
|
-
opts.on(
|
37
|
+
opts.on(
|
38
|
+
'-oFile.html',
|
39
|
+
'--output=File.html',
|
40
|
+
'Specify a path to write output, by default will be printed to STDOUT'
|
41
|
+
) do |value|
|
22
42
|
options[:output] = value
|
23
43
|
end
|
44
|
+
|
45
|
+
opts.on(
|
46
|
+
'-tTemplateName',
|
47
|
+
'--template=TemplateName',
|
48
|
+
'Specify the template name, available templates ' + templates.to_s
|
49
|
+
) do |value|
|
50
|
+
options[:template] = value
|
51
|
+
end
|
24
52
|
end.parse!
|
25
53
|
|
26
54
|
files = ARGV.empty? ? STDIN.read.lines : ARGV
|
@@ -28,8 +56,7 @@ files.map!(&:strip)
|
|
28
56
|
|
29
57
|
root = Dirtree::Node.new('/')
|
30
58
|
files.each { |file| root.insert(file.split('/')) }
|
31
|
-
|
32
|
-
template_file = File.join(templates_dir, 'tree.html.erb')
|
59
|
+
template_file = File.join(templates_dir, options[:template] + '.html.erb')
|
33
60
|
template = File.read(File.expand_path(template_file))
|
34
61
|
|
35
62
|
tree = root.as_json
|
data/lib/dirtree/version.rb
CHANGED
@@ -0,0 +1,111 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<meta charset="utf-8">
|
3
|
+
<style>
|
4
|
+
|
5
|
+
html, body{
|
6
|
+
height: 100%;
|
7
|
+
margin: 0;
|
8
|
+
padding: 0;
|
9
|
+
}
|
10
|
+
|
11
|
+
.node {
|
12
|
+
cursor: pointer;
|
13
|
+
}
|
14
|
+
|
15
|
+
.node:hover {
|
16
|
+
stroke: #000;
|
17
|
+
stroke-width: 1.5px;
|
18
|
+
}
|
19
|
+
|
20
|
+
.node--leaf {
|
21
|
+
fill: white;
|
22
|
+
}
|
23
|
+
|
24
|
+
.label {
|
25
|
+
font: 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
|
26
|
+
text-anchor: middle;
|
27
|
+
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff;
|
28
|
+
}
|
29
|
+
|
30
|
+
.label,
|
31
|
+
.node--root,
|
32
|
+
.node--leaf {
|
33
|
+
pointer-events: none;
|
34
|
+
}
|
35
|
+
|
36
|
+
</style>
|
37
|
+
<svg width="100%" height="100%"></svg>
|
38
|
+
<script src="https://d3js.org/d3.v4.min.js"></script>
|
39
|
+
<script>
|
40
|
+
// Copied from https://bl.ocks.org/mbostock/7607535
|
41
|
+
var width = window.innerWidth,
|
42
|
+
height = window.innerHeight;
|
43
|
+
var svg = d3.select("svg"),
|
44
|
+
margin = 20,
|
45
|
+
diameter = Math.min(width, height),
|
46
|
+
g = svg.append("g").attr("transform", "translate(" + diameter / 2 + "," + diameter / 2 + ")");
|
47
|
+
|
48
|
+
var color = d3.scaleLinear()
|
49
|
+
.domain([-1, 5])
|
50
|
+
.range(["hsl(152,80%,80%)", "hsl(228,30%,40%)"])
|
51
|
+
.interpolate(d3.interpolateHcl);
|
52
|
+
|
53
|
+
var pack = d3.pack()
|
54
|
+
.size([diameter - margin, diameter - margin])
|
55
|
+
.padding(2);
|
56
|
+
|
57
|
+
root = <%= tree.to_json %>;
|
58
|
+
root = d3.hierarchy(root)
|
59
|
+
.sum(function(d) { return d.children.length + 1; })
|
60
|
+
.sort(function(a, b) { return b.value - a.value; });
|
61
|
+
|
62
|
+
var focus = root,
|
63
|
+
nodes = pack(root).descendants(),
|
64
|
+
view;
|
65
|
+
|
66
|
+
var circle = g.selectAll("circle")
|
67
|
+
.data(nodes)
|
68
|
+
.enter().append("circle")
|
69
|
+
.attr("class", function(d) { return d.parent ? d.children ? "node" : "node node--leaf" : "node node--root"; })
|
70
|
+
.style("fill", function(d) { return d.children ? color(d.depth) : null; })
|
71
|
+
.on("click", function(d) { if (focus !== d) zoom(d), d3.event.stopPropagation(); });
|
72
|
+
|
73
|
+
var text = g.selectAll("text")
|
74
|
+
.data(nodes)
|
75
|
+
.enter().append("text")
|
76
|
+
.attr("class", "label")
|
77
|
+
.style("fill-opacity", function(d) { return d.parent === root ? 1 : 0; })
|
78
|
+
.style("display", function(d) { return d.parent === root ? "inline" : "none"; })
|
79
|
+
.text(function(d) { return d.data.name; });
|
80
|
+
|
81
|
+
var node = g.selectAll("circle,text");
|
82
|
+
|
83
|
+
svg
|
84
|
+
.style("background", color(-1))
|
85
|
+
.on("click", function() { zoom(root); });
|
86
|
+
|
87
|
+
zoomTo([root.x, root.y, root.r * 2 + margin]);
|
88
|
+
|
89
|
+
function zoom(d) {
|
90
|
+
var focus0 = focus; focus = d;
|
91
|
+
|
92
|
+
var transition = d3.transition()
|
93
|
+
.duration(d3.event.altKey ? 7500 : 750)
|
94
|
+
.tween("zoom", function(d) {
|
95
|
+
var i = d3.interpolateZoom(view, [focus.x, focus.y, focus.r * 2 + margin]);
|
96
|
+
return function(t) { zoomTo(i(t)); };
|
97
|
+
});
|
98
|
+
|
99
|
+
transition.selectAll("text")
|
100
|
+
.filter(function(d) { return d.parent === focus || this.style.display === "inline"; })
|
101
|
+
.style("fill-opacity", function(d) { return d.parent === focus ? 1 : 0; })
|
102
|
+
.on("start", function(d) { if (d.parent === focus) this.style.display = "inline"; })
|
103
|
+
.on("end", function(d) { if (d.parent !== focus) this.style.display = "none"; });
|
104
|
+
}
|
105
|
+
|
106
|
+
function zoomTo(v) {
|
107
|
+
var k = diameter / v[2]; view = v;
|
108
|
+
node.attr("transform", function(d) { return "translate(" + (d.x - v[0]) * k + "," + (d.y - v[1]) * k + ")"; });
|
109
|
+
circle.attr("r", function(d) { return d.r * k; });
|
110
|
+
}
|
111
|
+
</script>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dirtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emad Elsaid
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- lib/dirtree.rb
|
57
57
|
- lib/dirtree/node.rb
|
58
58
|
- lib/dirtree/version.rb
|
59
|
+
- templates/circles.html.erb
|
59
60
|
- templates/tree.html.erb
|
60
61
|
homepage: https://www.github.com/blazeeboy/dirtree
|
61
62
|
licenses:
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
80
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.6.
|
81
|
+
rubygems_version: 2.6.10
|
81
82
|
signing_key:
|
82
83
|
specification_version: 4
|
83
84
|
summary: display list of file paths as an interactive tree
|