fd 0.3.1 → 0.4.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/README.md +33 -1
- data/bin/fd +9 -4
- data/lib/fd/version.rb +1 -1
- data/lib/fd.rb +12 -6
- 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: 1122c17d4d0b0ca235ecffd2097f0f1f8e3144deb4e77fe9698291cb7f0e6156
|
4
|
+
data.tar.gz: 1a31a0f9c47596bcd62a38ebc497e360d5625af3535746a7e898a3f05103737c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a07fe67487ce00025e0e4e632563f6f6169f5e5e5b1ce812ddb2ef941ed62e2e697cf66b15bb979b93249333d23d4f8f24d6d8ac63446f5c653704ef52569329
|
7
|
+
data.tar.gz: ecf0d832fcae4d502e619501cdb57d70faa94fa1b0a933af68de699dcaf9b2d480894558892ebf7c4737d930c22869f3af3c14476f5d2548fc01a14b9e2b2731
|
data/README.md
CHANGED
@@ -34,8 +34,40 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
+
You can pass _file names_ on the command line:
|
38
|
+
|
39
|
+
```
|
40
|
+
fd [-w _number_] [file_names]
|
37
41
|
```
|
38
|
-
|
42
|
+
|
43
|
+
For example:
|
44
|
+
```bash
|
45
|
+
> echo "Bacon ipsum dolor amet short ribs flank irure filet mignon brisket buffalo est porchetta." | fd -w 7
|
46
|
+
STDIN
|
47
|
+
42 61 63 6f 6e 20 69 | B a c o n __ i
|
48
|
+
70 73 75 6d 20 64 6f | p s u m __ d o
|
49
|
+
6c 6f 72 20 61 6d 65 | l o r __ a m e
|
50
|
+
74 20 73 68 6f 72 74 | t __ s h o r t
|
51
|
+
20 72 69 62 73 20 66 | __ r i b s __ f
|
52
|
+
6c 61 6e 6b 20 69 72 | l a n k __ i r
|
53
|
+
75 72 65 20 66 69 6c | u r e __ f i l
|
54
|
+
65 74 20 6d 69 67 6e | e t __ m i g n
|
55
|
+
6f 6e 20 62 72 69 73 | o n __ b r i s
|
56
|
+
6b 65 74 20 62 75 66 | k e t __ b u f
|
57
|
+
66 61 6c 6f 20 65 73 | f a l o __ e s
|
58
|
+
74 20 70 6f 72 63 68 | t __ p o r c h
|
59
|
+
65 74 74 61 2e 0a | e t t a . LF```
|
60
|
+
|
61
|
+
You can also pipe input to STDIN:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
> echo "Put something into STDIN" | be bin/fd -w 5
|
65
|
+
STDIN
|
66
|
+
50 75 74 20 73 | P u t __ s
|
67
|
+
6f 6d 65 74 68 | o m e t h
|
68
|
+
69 6e 67 20 69 | i n g __ i
|
69
|
+
6e 74 6f 20 53 | n t o __ S
|
70
|
+
54 44 49 4e 0a | T D I N LF
|
39
71
|
```
|
40
72
|
|
41
73
|
## Development
|
data/bin/fd
CHANGED
@@ -9,7 +9,7 @@ arguments = OpenStruct.new
|
|
9
9
|
arguments.width = 10
|
10
10
|
|
11
11
|
options = OptionParser.new do |opts|
|
12
|
-
opts.banner = "Usage: #{File.basename __FILE__} [options] file_names"
|
12
|
+
opts.banner = "Usage: #{File.basename __FILE__} [options] [file_names]"
|
13
13
|
|
14
14
|
opts.on('-w', '--width=WIDTH [Integer]', Integer, 'Display upto _width_ bytes per row, optional, default is 10') do |width|
|
15
15
|
arguments.width = width
|
@@ -17,6 +17,7 @@ options = OptionParser.new do |opts|
|
|
17
17
|
|
18
18
|
opts.on('-h', '--help', 'Display using this help') do
|
19
19
|
puts opts
|
20
|
+
puts '', 'When no file names a given fd reads from STDIN.'
|
20
21
|
exit
|
21
22
|
end
|
22
23
|
|
@@ -27,7 +28,7 @@ options = OptionParser.new do |opts|
|
|
27
28
|
end
|
28
29
|
|
29
30
|
begin
|
30
|
-
ARGV.push('-h') if ARGV.empty?
|
31
|
+
ARGV.push('-h') if ARGV.empty? && ARGF.eof?
|
31
32
|
options.parse!
|
32
33
|
rescue OptionParser::InvalidArgument
|
33
34
|
puts "fd doesn't work, this way:"
|
@@ -37,6 +38,10 @@ end
|
|
37
38
|
|
38
39
|
file_dumper = Fd.new(arguments.width)
|
39
40
|
|
40
|
-
ARGV.
|
41
|
-
|
41
|
+
if ARGV.size.positive?
|
42
|
+
ARGV.each do |fn|
|
43
|
+
file_dumper.dump_file(fn)
|
44
|
+
end
|
45
|
+
else
|
46
|
+
file_dumper.dump_stdin(STDIN.read)
|
42
47
|
end
|
data/lib/fd/version.rb
CHANGED
data/lib/fd.rb
CHANGED
@@ -45,18 +45,24 @@ class Fd
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# dumps the given file _file_name_ to stdout.
|
48
|
-
def dump(
|
49
|
-
puts file_name
|
50
|
-
content = File.read(file_name)
|
48
|
+
def dump(content)
|
51
49
|
raise "Not the expected encoding of UFT-8, got #{content.encoding}" unless content.encoding == Encoding::UTF_8
|
52
50
|
|
53
51
|
initialize_fields(content)
|
54
|
-
while @char_index < @chars.size
|
55
|
-
process_current_character
|
56
|
-
end
|
52
|
+
process_current_character while @char_index < @chars.size
|
57
53
|
print_single_line unless line.empty?
|
58
54
|
end
|
59
55
|
|
56
|
+
def dump_file(file_name)
|
57
|
+
puts file_name
|
58
|
+
dump(File.read(file_name))
|
59
|
+
end
|
60
|
+
|
61
|
+
def dump_stdin(content)
|
62
|
+
puts 'STDIN'
|
63
|
+
dump(content)
|
64
|
+
end
|
65
|
+
|
60
66
|
private
|
61
67
|
|
62
68
|
def process_current_character
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephan Kämper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard-bundler
|