ix-cli 0.0.25 → 0.0.27

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f91aade16c9caf38a86cbb707cb450d7a8fc9b7f4c6c1b66f2b11c6cc1e1fd5c
4
- data.tar.gz: 02f508ac05321cc4154d34070e0c7d78bf06fec9a8206fcdbe56b4f2d3e78826
3
+ metadata.gz: d96878e4367fe4bb7b6732ebef36181393faf9bf99cb936939a0140cc14f2382
4
+ data.tar.gz: 35c9e1ab1970884af9b6852ab3ee8686d9e37956fef09440d0c0d1143fb7bde3
5
5
  SHA512:
6
- metadata.gz: 3ae606dcb64a65ede528f1751f7ed990d512c59c9aac7ed0a38ead30664d93deb58c01cdee5ba7d330babd69180b76f82becbc290c83d1eda53439d8eceb6e01
7
- data.tar.gz: c02fc0ffdcb1943467d74400542bec8d9b836fb80f202dfe747796714560de7f5970bc37af32af58997f163ec88184520030f1f8f4fb2686950c8803a8960678
6
+ metadata.gz: 8fdac8bfd572c70bb471231c950145bc5d1ed1d6edb95a97a8ec1723bb4f776ebe8ec41c6817ecc272cab265da4c655b52404db425705f8b2c5f5446577bf6ee
7
+ data.tar.gz: 18b31e415c8e7f2235d0d4f29aebf48cfab503e8a871ab52952179a5b68871f34cb5ac47247748b780edb5b9088f97b065bac326e00b08a5193e7e74a9b59c7d
data/bin/ix-hls CHANGED
@@ -10,6 +10,29 @@
10
10
 
11
11
  require 'isna'
12
12
 
13
+ require 'optparse'
14
+
15
+ options = {}
16
+ options[:delimiter] = ':'
17
+
18
+ OptionParser.new do |opts|
19
+
20
+ opts.banner = "Usage: #{$0} [OPTIONS]"
21
+
22
+ opts.on('-d', '--delimiter [STRING]', 'Delimiter.') do |value|
23
+ options[:delimiter] = value
24
+ end
25
+
26
+ end.parse!
27
+
28
+ required_options = [:delimiter]
29
+ required_options.each do |option|
30
+ unless options[option]
31
+ $stderr.puts "Can not run #{option.to_s} was not given."
32
+ exit 1
33
+ end
34
+ end
35
+
13
36
  abort 'No pattern given' if ARGV[0].nil?
14
37
 
15
38
  trap('SIGINT') { }
@@ -17,9 +40,11 @@ trap('SIGINT') { }
17
40
  $stdout.sync = true
18
41
 
19
42
  STDIN.each_line do |line|
43
+ line.chomp!
20
44
  ARGV.each do |arg|
21
- chunks = arg.split(':')
22
- puts line.gsub(/(#{chunks[0]})/i) { |x| $1.to_ansi.send(chunks[1].to_sym).to_s }
45
+ chunks = arg.split(options[:delimiter])
46
+ line.gsub!(/(#{chunks[0]})/i) { |x| $1.to_ansi.send(chunks[1].to_sym).to_s }
23
47
  end
48
+ puts line
24
49
  end
25
50
 
data/bin/ix-json-filter CHANGED
@@ -5,6 +5,7 @@ require 'json'
5
5
  require 'optparse'
6
6
 
7
7
  options = {}
8
+ options[:behavior] = 'add'
8
9
 
9
10
  OptionParser.new do |opts|
10
11
 
@@ -18,14 +19,17 @@ OptionParser.new do |opts|
18
19
  options[:field] = value
19
20
  end
20
21
 
21
-
22
22
  opts.on('-m', '--match [REGEX]', 'Match.') do |value|
23
23
  options[:match] = value
24
24
  end
25
25
 
26
+ opts.on('-b', '--behavior [STRING]', 'Behavior can be either [add|remove]') do |value|
27
+ options[:behavior] = ['add', 'remove'].include?(value) ? value : 'add'
28
+ end
29
+
26
30
  end.parse!
27
31
 
28
- required_options = [:match]
32
+ required_options = [:match, :behavior]
29
33
  required_options.each do |option|
30
34
  unless options[option]
31
35
  $stderr.puts "Can not run #{option.to_s} was not given."
@@ -41,14 +45,27 @@ end
41
45
  STDIN.each_line do |line|
42
46
  begin
43
47
  json = JSON.parse(line)
44
- if options[:field]
45
- if json[options[:field]].to_s =~ /#{options[:match]}/
46
- puts line
48
+ if options[:behavior] == 'add'
49
+ if options[:field]
50
+ if json[options[:field]].to_s =~ /#{options[:match]}/
51
+ puts line
52
+ end
47
53
  end
48
- end
49
- if options[:value]
50
- if json.values.any? { |v| v.to_s =~ /#{options[:match]}/ }
51
- puts line
54
+ if options[:value]
55
+ if json.values.any? { |v| v.to_s =~ /#{options[:match]}/ }
56
+ puts line
57
+ end
58
+ end
59
+ else
60
+ if options[:field]
61
+ if json[options[:field]].to_s !~ /#{options[:match]}/
62
+ puts line
63
+ end
64
+ end
65
+ if options[:value]
66
+ if json.values.none? { |v| v.to_s =~ /#{options[:match]}/ }
67
+ puts line
68
+ end
52
69
  end
53
70
  end
54
71
  rescue JSON::ParserError => e
data/bin/ix-linkify CHANGED
@@ -3,6 +3,28 @@
3
3
  require 'net/http'
4
4
  require 'nokogiri'
5
5
  require 'open-uri'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ options[:output] = 'text'
10
+
11
+ OptionParser.new do |opts|
12
+
13
+ opts.banner = "Usage: #{$0} [OPTIONS]"
14
+
15
+ opts.on('-o', '--output [STRING]', 'Output.') do |value|
16
+ options[:output] = value
17
+ end
18
+
19
+ end.parse!
20
+
21
+ required_options = [:output]
22
+ required_options.each do |option|
23
+ unless options[option]
24
+ $stderr.puts "Can not run #{option.to_s} was not given."
25
+ exit 1
26
+ end
27
+ end
6
28
 
7
29
  class Mock
8
30
  attr_accessor :title
@@ -10,13 +32,19 @@ end
10
32
 
11
33
  counter = 0
12
34
 
35
+ if options[:output] == 'html'
36
+ puts "<ol>"
37
+ end
38
+
13
39
  STDIN.each_line do |line|
14
40
  next if line.chomp == ''
15
41
  counter += 1
16
42
  url = line.chomp
17
43
  begin
18
- doc = Nokogiri::HTML(open(url))
44
+ data = Net::HTTP.get(URI.parse(url))
45
+ doc = Nokogiri::HTML(data)
19
46
  rescue => e
47
+ $stderr.puts e.message
20
48
  doc = Mock.new
21
49
  doc.title = url
22
50
  end
@@ -24,12 +52,26 @@ STDIN.each_line do |line|
24
52
  doc = Mock.new
25
53
  doc.title = url
26
54
  end
27
- template = "%s - %s\n%s\n\n"
28
- title = doc.title
29
- title.chomp!
30
- title.gsub!(/\n/, '')
31
- title.gsub!(/^\s+/, '')
32
- title.gsub!(/\s+$/, '')
33
- bindings = [counter, title, url]
34
- puts template % bindings
55
+ if options[:output] == 'text'
56
+ template = "%s - %s\n%s\n\n"
57
+ title = doc.title
58
+ title.chomp!
59
+ title.gsub!(/\n/, '')
60
+ title.gsub!(/^\s+/, '')
61
+ title.gsub!(/\s+$/, '')
62
+ bindings = [counter, title, url]
63
+ puts template % bindings
64
+ elsif options[:output] == 'html'
65
+ title = doc.title
66
+ title.chomp!
67
+ title.gsub!(/\n/, '')
68
+ title.gsub!(/^\s+/, '')
69
+ title.gsub!(/\s+$/, '')
70
+ # bindings = [counter, title, url, url]
71
+ puts "<li><a href='#{url}'>#{title}</a></li>"
72
+ end
73
+ end
74
+
75
+ if options[:output] == 'html'
76
+ puts "</ol>"
35
77
  end
data/bin/ix-pad-char ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {}
6
+ options[:pad] = 4
7
+ options[:fill] = '─'
8
+ options[:char] = '['
9
+
10
+ OptionParser.new do |opts|
11
+
12
+ opts.banner = "Usage: #{$0} [OPTIONS]"
13
+
14
+ opts.on('-c', '--char [STRING]', 'Char to use as padding target.') do |value|
15
+ options[:char] = value
16
+ end
17
+
18
+ opts.on('-f', '--fill [STRING]', 'Char to use as filling.') do |value|
19
+ options[:fill] = value
20
+ end
21
+
22
+ opts.on('-p', '--pad [NUMBER]', 'Padd to add to the fill.') do |value|
23
+ options[:pad] = value.to_i
24
+ end
25
+
26
+ end.parse!
27
+
28
+ required_options = [:char, :pad, :fill]
29
+ required_options.each do |option|
30
+ unless options[option]
31
+ $stderr.puts "Can not run #{option.to_s} was not given."
32
+ exit 1
33
+ end
34
+ end
35
+
36
+ items = []
37
+
38
+ STDIN.each_line do |line|
39
+ items << line.chomp
40
+ end
41
+
42
+ max_index_of_char = items.map { |item| item.index(options[:char]) }.max
43
+ char = options[:char]
44
+
45
+ if char == ' '
46
+ char = '\s'
47
+ end
48
+
49
+ if char == '['
50
+ char = '\['
51
+ end
52
+
53
+ REGEX = Regexp.new("^([^#{char}]+)(#{char})(.*$)")
54
+
55
+ # puts "Max index of char: #{max_index_of_char}"
56
+
57
+ items.each do |item|
58
+ next unless REGEX.match(item)
59
+ item.gsub(REGEX) do |match|
60
+ puts "#{($1) + ($2).rjust((max_index_of_char) - $1.size + options[:pad], options[:fill])}#{$3}"
61
+ end
62
+ end
63
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ STDIN.each_line do |line|
6
+ next if line.strip.empty?
7
+ begin
8
+ object = JSON.parse(JSON.parse(line))
9
+ puts object.to_json
10
+ rescue => e
11
+ $stderr.puts "Error: #{e.message}"
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel
@@ -207,6 +207,7 @@ executables:
207
207
  - ix-occurrence
208
208
  - ix-open
209
209
  - ix-pad
210
+ - ix-pad-char
210
211
  - ix-parse
211
212
  - ix-pass
212
213
  - ix-path
@@ -278,6 +279,7 @@ executables:
278
279
  - ix-stream
279
280
  - ix-string-similarity
280
281
  - ix-string-similarity2
282
+ - ix-string-to-json
281
283
  - ix-strip
282
284
  - ix-substract
283
285
  - ix-success
@@ -513,6 +515,7 @@ files:
513
515
  - bin/ix-occurrence
514
516
  - bin/ix-open
515
517
  - bin/ix-pad
518
+ - bin/ix-pad-char
516
519
  - bin/ix-parse
517
520
  - bin/ix-pass
518
521
  - bin/ix-path
@@ -584,6 +587,7 @@ files:
584
587
  - bin/ix-stream
585
588
  - bin/ix-string-similarity
586
589
  - bin/ix-string-similarity2
590
+ - bin/ix-string-to-json
587
591
  - bin/ix-strip
588
592
  - bin/ix-substract
589
593
  - bin/ix-success