du_pretty 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/du_pretty/cli.rb +16 -4
- data/lib/du_pretty/version.rb +1 -1
- data/lib/du_pretty.rb +45 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61dc0af33ffecb01858522e4fa90309c5e04c6942bef5d8dbcbca1ec24f0aad3
|
4
|
+
data.tar.gz: 966e1e39727763f52a18a8a1fe418cfc845f1e3e37556adceb960c31d50e239e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f399efd4c2e46e23b22766a9d0c1cb589d6e7851064fafa969f9a68b6a36d90ff63c35f547efd10e8aef3a6d10023623358776db7ea2c3189efb85bbe14c0494
|
7
|
+
data.tar.gz: 65d2be03a70889c77f149f097995768875f20bf70665c36f4b1eee012cdad24d4280da6255e97ebcab68c228716c4b3395da8e57cb911e15e403f45e15dc0a0c
|
data/Gemfile.lock
CHANGED
data/lib/du_pretty/cli.rb
CHANGED
@@ -9,14 +9,26 @@ module DuPretty
|
|
9
9
|
option :min_mbyte, type: :numeric
|
10
10
|
option :min_kbyte, type: :numeric
|
11
11
|
option :depth, type: :numeric, aliases: :d
|
12
|
+
option :sort, aliases: :s, type: :boolean
|
13
|
+
option :all, aliases: :a, type: :boolean
|
14
|
+
option :tree, type: :boolean, default: true
|
15
|
+
|
12
16
|
def path(path = '.')
|
13
17
|
min_kbyte = [(options[:min_gbyte] || 0) * 1024 * 1024, (options[:min_mbyte] || 0) * 1024, (options[:min_kbyte] || 0)].max
|
14
|
-
|
18
|
+
du_wrapper = DuWrapper.new(
|
15
19
|
path,
|
16
20
|
min_kbyte: min_kbyte,
|
17
|
-
depth: options[:depth]
|
18
|
-
|
19
|
-
|
21
|
+
depth: options[:depth],
|
22
|
+
with_files: options[:all],
|
23
|
+
)
|
24
|
+
result = if options[:sort]
|
25
|
+
du_wrapper.sorted
|
26
|
+
elsif options[:tree] == false
|
27
|
+
du_wrapper.original
|
28
|
+
else
|
29
|
+
du_wrapper.tree
|
30
|
+
end
|
31
|
+
print result + "\n"
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
data/lib/du_pretty/version.rb
CHANGED
data/lib/du_pretty.rb
CHANGED
@@ -6,39 +6,62 @@ require 'du_pretty/cli'
|
|
6
6
|
|
7
7
|
module DuPretty
|
8
8
|
class DuWrapper
|
9
|
-
def initialize(path, min_kbyte: 0, depth: nil)
|
9
|
+
def initialize(path, min_kbyte: 0, depth: nil, with_files: false)
|
10
10
|
@path = File.expand_path(path, Pathname.pwd)
|
11
11
|
@min_kbyte = min_kbyte
|
12
12
|
@depth = depth
|
13
|
+
@with_files = with_files
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
def original
|
17
|
+
filtered_disk_usages.map(&:pretty).join("\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
def sorted
|
21
|
+
filtered_disk_usages.sort_by(&:kbyte).map(&:pretty).join("\n")
|
22
|
+
end
|
23
|
+
|
24
|
+
def tree
|
25
|
+
filtered_disk_usages.reverse.map(&:tree_format).join("\n")
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
25
29
|
|
26
30
|
def du
|
27
|
-
options =
|
28
|
-
|
31
|
+
options = [
|
32
|
+
@depth.nil? ? nil : "-d #{@depth}",
|
33
|
+
@with_files ? '-a' : nil,
|
34
|
+
'-k'
|
35
|
+
]
|
36
|
+
`du #{options.join(' ')} #{@path}`
|
37
|
+
end
|
38
|
+
|
39
|
+
def disk_usages
|
40
|
+
xs = du.split("\n").map { |line| DiskUsage.new(line, @path) }
|
41
|
+
total = xs.map(&:kbyte).max
|
42
|
+
xs.map { |x| DiskUsage.new(x.raw, @path, total: total) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def filtered_disk_usages
|
46
|
+
disk_usages.select { |x| x.kbyte >= @min_kbyte }
|
29
47
|
end
|
30
48
|
|
31
49
|
class DiskUsage
|
32
50
|
attr_accessor :raw, :kbyte, :path
|
33
51
|
|
34
|
-
def initialize(raw, root)
|
52
|
+
def initialize(raw, root, total: nil)
|
35
53
|
@raw = raw
|
36
54
|
@root = root
|
37
55
|
@kbyte = raw.split("\t").compact[0].to_i
|
38
56
|
@path = raw.split("\t").compact[1]
|
57
|
+
@total = total
|
39
58
|
end
|
40
59
|
|
41
60
|
def pretty
|
61
|
+
pretty_byte + "\t." + relative_path
|
62
|
+
end
|
63
|
+
|
64
|
+
def tree_format
|
42
65
|
pretty_path + ' ' + pretty_byte
|
43
66
|
end
|
44
67
|
|
@@ -57,21 +80,21 @@ module DuPretty
|
|
57
80
|
gb = mb / 1024
|
58
81
|
if gb.positive?
|
59
82
|
if gb > 10
|
60
|
-
"#{gb}GB".red
|
83
|
+
"#{gb}GB (#{percentage})".red
|
61
84
|
else
|
62
|
-
"#{gb}GB".light_red
|
85
|
+
"#{gb}GB (#{percentage})".light_red
|
63
86
|
end
|
64
87
|
elsif mb.positive?
|
65
88
|
if mb > 500
|
66
|
-
"#{mb}MB".yellow
|
89
|
+
"#{mb}MB (#{percentage})".yellow
|
67
90
|
else
|
68
|
-
"#{mb}MB".light_yellow
|
91
|
+
"#{mb}MB (#{percentage})".light_yellow
|
69
92
|
end
|
70
93
|
else
|
71
94
|
if @kbyte > 500
|
72
|
-
"#{@kbyte}KB".green
|
95
|
+
"#{@kbyte}KB (#{percentage})".green
|
73
96
|
else
|
74
|
-
"#{@kbyte}KB".light_green
|
97
|
+
"#{@kbyte}KB (#{percentage})".light_green
|
75
98
|
end
|
76
99
|
end
|
77
100
|
end
|
@@ -83,6 +106,11 @@ module DuPretty
|
|
83
106
|
spaces + tree_symbol + basename
|
84
107
|
end
|
85
108
|
|
109
|
+
def percentage
|
110
|
+
percentage = @kbyte * 1.0 / @total * 100
|
111
|
+
"#{percentage.ceil}%"
|
112
|
+
end
|
113
|
+
|
86
114
|
def relative_path
|
87
115
|
@path.sub(/^#{@root}/, '')
|
88
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: du_pretty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Katsuma Narisawa
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.7.
|
126
|
+
rubygems_version: 2.7.6
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Simple wrapper for "du" to pretty print.
|