ese 1.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/bin/ese +152 -0
  3. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1cd3880a86e4719d542ceeddc30057bdb946414
4
+ data.tar.gz: 91733c7b6715bd6a3360384422f59aabb7bb5671
5
+ SHA512:
6
+ metadata.gz: 7336d042ff72092261f2f5dbb98a02828ebf82b051b42302b8e9643b00fac9fdeeb2eae46ce22c5f42e889c10a8b6a595a30c139ffa5f993a88f244588813cd1
7
+ data.tar.gz: df3f08912851c7f5828f18b4f25dd0d94e072bdc549d23973d2553691145013e9fc8e8b8b7a8770be7506c2ec65793a94dab2ca7342e2286db4aa716ea6f68eb
data/bin/ese ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'io/console'
4
+
5
+ USAGE = <<-eoc
6
+
7
+ USAGE: ese [include/-i|exclude/-x|find/-f|sub/-s|gsub/-g|help/-h] [REGEXP FILE]
8
+
9
+ EXPLANATION OF COMMANDS
10
+
11
+ include(-i):
12
+ print all lines matching REGEXP
13
+ ~> ese -i '/foo$/' test.txt
14
+ # print all lines of test.txt ending with "foo"
15
+
16
+ exclude(--x):
17
+ print all lines not matching REGEXP
18
+ ~> ese exclude '/^bar.*baz$/i' test.txt
19
+ # don't print the lines of test.txt starting
20
+ # with "bar" and ending with "baz", not regarding the case
21
+
22
+ find(-f):
23
+ print the text matching REGEXP
24
+ ~> cat test1.txt test2.txt | ese -f '/META_([^_]+)_ENDMETA/' | head -n1 | base64 -d
25
+ # concatenate files test1.txt and test2.txt, then
26
+ # find base64 encoded information between
27
+ # "META_" and "_ENDMETA" and decode the first occurrence
28
+
29
+ sub(-s)[maybe still a bit buggy]:
30
+ replace the nth occurrence of REGEXP in the text with a string
31
+ ~> ese sub '2/[Hh]acker/h4\\(K3r/' article.txt
32
+ # replace the second occurence of 'hacker'(case insensitive)
33
+ # with 'h4\\(K3r' to make it look more cyberish
34
+
35
+ gsub(-g):
36
+ replace ALL occurrences of REGEXP in the text with a string
37
+ ~> ese -g '/genius/IDIOT/i' cv.txt
38
+ # replace all occurrences of 'genius' in cv.txt
39
+ # by "IDIOT", not regarding the case
40
+ # * insert "that's the evilest thing i can imagine" meme here *
41
+
42
+ help(-h):
43
+ show this help
44
+
45
+ Read more about regular expressions in Ruby here:
46
+ http://ruby-doc.org/core-2.4.1/Regexp.html
47
+
48
+ eoc
49
+
50
+ #abort(USAGE)
51
+
52
+ def parse_mode(mode)
53
+ $mode = case mode
54
+ when "-i","include"
55
+ :include
56
+ when "-x","exclude"
57
+ :exclude
58
+ when "-f","find"
59
+ :find
60
+ when "-s","sub"
61
+ :sub
62
+ when "-g","gsub"
63
+ :gsub
64
+ when "-h","help"
65
+ puts USAGE
66
+ exit 0
67
+ else
68
+ abort( "\nUnknown option '#{mode}'\n" << USAGE )
69
+ end
70
+ end
71
+
72
+ def make_regex(*args)
73
+ args.flatten!
74
+ if args.length==1 # $mode != :sub
75
+ options = {i: 1, x: 2, m: 4}
76
+ options_str = args.first.split("/").last.split("")
77
+ option_bits = options.to_a.select{|i|options_str.include? i[0].to_s}.to_h.values.sum
78
+ Regexp.new(args.first, option_bits)
79
+ else # $mode.to_s.match /^g?sub$/
80
+ options = {i: 1, x: 2, m: 4}
81
+ options_str = args[3].split("")
82
+ option_bits = options.to_a.select{|i|options_str.include? i[0].to_s}.to_h.values.sum
83
+ Regexp.new(args[1], option_bits)
84
+ end
85
+ end
86
+
87
+ ARGV.length==2 or ARGV.length==3 or abort(USAGE)
88
+
89
+ mode, regexp = ARGV.shift(2)
90
+ parse_mode(mode)
91
+
92
+ unless %w(sub gsub).include? $mode.to_s
93
+ $REGEX = Regexp.new(regexp.match(%r{^/(.+)/$})[1])
94
+ else
95
+ $REGEX = regexp.split("/")
96
+ $REGEX = $REGEX.concat Array.new(4-$REGEX.length){""}
97
+ end
98
+
99
+ while (l=gets)
100
+ l.chomp!
101
+ $l = l
102
+ case $mode
103
+
104
+ when :include
105
+ l.match($REGEX) and puts(l)
106
+
107
+ when :exclude
108
+ l.match($REGEX) or puts(l)
109
+
110
+ when :find
111
+ m = l.match($REGEX)
112
+ m and puts(m)
113
+
114
+ when :sub
115
+ larr = [l]
116
+ while (l=gets); larr << l.chomp; end
117
+ l_full = larr.join("\n")
118
+
119
+ #<<-eoc
120
+ arr_regex = make_regex($REGEX)
121
+ ms = l_full.scan(arr_regex)
122
+ $occ ||= 0
123
+ $mp_a ||= 0
124
+ unless $REGEX[0].to_i==1
125
+ until $occ == $REGEX[0].to_i-1
126
+ $occ += 1
127
+ $mp = (arr_regex =~ ($l2 or l_full))
128
+ begin
129
+ $mp_a += (arr_regex =~ ($l2 or l_full))
130
+ rescue TypeError
131
+ puts larr.join("\n")
132
+ exit
133
+ end
134
+ $mp += ($l2 or l_full).match(arr_regex).to_s.length
135
+ $mp_a += ($l2 or l_full).match(arr_regex).to_s.length
136
+ $l2 = l_full[$mp_a,l_full.length]
137
+ end
138
+ $l2.sub!(arr_regex,$REGEX[2])
139
+ l_full = larr.join("\n")[0,$mp_a]+$l2
140
+ else
141
+ l_full.sub!(arr_regex,$REGEX[2])
142
+ end
143
+ puts l_full
144
+
145
+ when :gsub
146
+ arr_regex = make_regex $REGEX
147
+ puts l.gsub(arr_regex,$REGEX[2])
148
+
149
+ end
150
+ end
151
+
152
+ $l or abort(USAGE)
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ese
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ platform: ruby
6
+ authors:
7
+ - sesshomariu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: An alternative stream editor to make editing streams easier
14
+ email:
15
+ executables:
16
+ - ese
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/ese
21
+ homepage:
22
+ licenses:
23
+ - GPL-3.0
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.6.11
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Easier Stream Editor
45
+ test_files: []
46
+ has_rdoc: