icersplicer 0.2.8 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/icersplicer +72 -28
- data/examples/keywords.ice +20 -0
- data/lib/icersplicer.rb +49 -12
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79a6b544dd7773a013878c6e2ba86254a45dd389
|
4
|
+
data.tar.gz: 7acbff17920844192fb8a3f5d8e97be1a156d569
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78d1cfaf9f36116a67727f820e49277f69590d40763df5cd2951f281e0c01ca51ea3a2007851a620877be6cab5250ced548f77f714ff5acfb717858a861be627
|
7
|
+
data.tar.gz: 2262de63b30956f95f8dc41bcfdc216d50cb6120c8fcf9fbd9f45358a2bd4a4e50e371df9f6c671fb378592b18e07061b8983be988b5d165740f82bd737d62c2
|
data/bin/icersplicer
CHANGED
@@ -34,7 +34,9 @@ opts = GetoptLong.new(
|
|
34
34
|
[ '--skipblank', '-b', GetoptLong::NO_ARGUMENT ],
|
35
35
|
[ '--quiet', '-q', GetoptLong::OPTIONAL_ARGUMENT],
|
36
36
|
[ '--outputfile', '-o', GetoptLong::OPTIONAL_ARGUMENT],
|
37
|
-
[ '--countlines', '-c', GetoptLong::OPTIONAL_ARGUMENT]
|
37
|
+
[ '--countlines', '-c', GetoptLong::OPTIONAL_ARGUMENT],
|
38
|
+
[ '--grep', '-g', GetoptLong::REQUIRED_ARGUMENT],
|
39
|
+
[ '--nohighlighter', '-t', GetoptLong::NO_ARGUMENT ]
|
38
40
|
)
|
39
41
|
|
40
42
|
opts.each do |opt, arg|
|
@@ -42,21 +44,26 @@ opts.each do |opt, arg|
|
|
42
44
|
when '--help'
|
43
45
|
helper = "\e[1;34mWelcome to Icersplicer #{VERSION}\e[0m\ \n"
|
44
46
|
helper << "\e[1;34m============================\e[0m\ \n"
|
45
|
-
helper << %
|
47
|
+
helper << %Q[
|
46
48
|
-h, --help '-h':
|
47
49
|
show help
|
48
50
|
--lineoffset '-l' INTEGER
|
49
51
|
--linelimit '-n' INTEGER
|
50
52
|
--inputfile '-f' filename
|
51
53
|
--skiplines '-s' LINE NUMBERS 3,5,6
|
52
|
-
--skipblank '-b' NO ARGUMENTS
|
54
|
+
--skipblank '-b' NO ARGUMENTS ( Ommit blank lines )
|
53
55
|
--quiet '-q' NO ARGUMENTS
|
54
56
|
--outputfile '-o' filename
|
55
57
|
--countlines '-c' Counts the lines of a file
|
58
|
+
--grep '-g' Filter data
|
59
|
+
--nohighlighter '-t' NO ARGUMENTS ( Turns off syntax hightlighting )
|
56
60
|
|
57
61
|
Example:
|
58
62
|
|
59
|
-
icersplicer -f inputfile --lineoffset 0 --linelimit 10 -s 3,6,9 -o outputfile
|
63
|
+
icersplicer -f inputfile --lineoffset 0 --linelimit 10 -s 3,6,9,10-15 -o outputfile
|
64
|
+
|
65
|
+
TIPS: Create a custom keywords list in your #{Dir.home}/.icersplicer/keywords.ice
|
66
|
+
|
60
67
|
|
61
68
|
Written by Brian Hood
|
62
69
|
]
|
@@ -75,10 +82,27 @@ Written by Brian Hood
|
|
75
82
|
puts "Outputfile: #{@outputfile}"
|
76
83
|
when '--skiplines'
|
77
84
|
@skip_lines = Array.new
|
78
|
-
arg.to_s.split(",").each {|n|
|
85
|
+
arg.to_s.split(",").each {|n|
|
86
|
+
@skip_lines << n.to_i
|
87
|
+
# Allow line ranges
|
88
|
+
min = n.split("-")[0].to_i
|
89
|
+
max = n.split("-")[1].to_i
|
90
|
+
unless n.split("-")[1] == nil
|
91
|
+
begin
|
92
|
+
if min > max and max != 0
|
93
|
+
return false
|
94
|
+
end
|
95
|
+
rescue
|
96
|
+
puts "Range Error: Minimun value can't be more than Maxiumun Range value"
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
min.upto(max) {|s|
|
100
|
+
@skip_lines << s unless @skip_lines[@skip_lines.size - 1] == s
|
101
|
+
}
|
102
|
+
end
|
103
|
+
}
|
79
104
|
when '--skipblank'
|
80
105
|
@skipblank = "SKIP"
|
81
|
-
puts @skipblank
|
82
106
|
when '--quiet'
|
83
107
|
if arg == "true"
|
84
108
|
@quiet_mode = true
|
@@ -87,6 +111,10 @@ Written by Brian Hood
|
|
87
111
|
end
|
88
112
|
when '--countlines'
|
89
113
|
@countlines = true
|
114
|
+
when '--grep'
|
115
|
+
@grep = arg.to_s
|
116
|
+
when '--nohighlighter'
|
117
|
+
@nohighlighter = "OFF"
|
90
118
|
end
|
91
119
|
end
|
92
120
|
|
@@ -124,33 +152,49 @@ unless File.exist?("#{inputfile}")
|
|
124
152
|
exit
|
125
153
|
end
|
126
154
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
155
|
+
def text_processor(data)
|
156
|
+
unless instance_variable_defined?("@nohighlighter")
|
157
|
+
data = text_highlighter(data)
|
158
|
+
return data
|
159
|
+
else
|
160
|
+
return data
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
begin
|
165
|
+
File.open(inputfile) {|n|
|
166
|
+
n.each_line {|data|
|
167
|
+
data_orig = data.clone
|
168
|
+
unless lineoffset > increment_offset
|
169
|
+
unless linelimit == 0
|
170
|
+
unless increment_limit > linelimit
|
171
|
+
unless instance_variable_defined?("@skipblank") and data.strip == ""
|
172
|
+
unless instance_variable_defined?("@grep") and data =~ %r=#{@grep}=
|
173
|
+
print_to_screen(linecounter, text_processor(data), quietmode) unless skip(linecounter)
|
174
|
+
if instance_variable_defined?("@outputfile")
|
175
|
+
processdata(data_orig, outputfile, quietmode) unless skip(linecounter)
|
176
|
+
end
|
177
|
+
end
|
137
178
|
end
|
138
179
|
end
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
180
|
+
else
|
181
|
+
unless instance_variable_defined?("@skipblank") and data.strip == ""
|
182
|
+
unless instance_variable_defined?("@grep") and data =~ %r=#{@grep}=
|
183
|
+
print_to_screen(linecounter, text_processor(data), quietmode) unless skip(linecounter)
|
184
|
+
if instance_variable_defined?("@outputfile")
|
185
|
+
processdata(data_orig, outputfile, quietmode) unless skip(linecounter)
|
186
|
+
end
|
187
|
+
end
|
145
188
|
end
|
146
189
|
end
|
190
|
+
increment_limit += 1
|
147
191
|
end
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
linecounter += 1
|
192
|
+
increment_offset += 1
|
193
|
+
linecounter += 1
|
194
|
+
}
|
152
195
|
}
|
153
|
-
|
154
|
-
|
196
|
+
rescue Errno::EPIPE
|
197
|
+
puts "Closing session due to broken pipe"
|
198
|
+
end
|
155
199
|
closefile if instance_variable_defined?("@exp")
|
156
200
|
stats(inputfile, outputfile)
|
@@ -0,0 +1,20 @@
|
|
1
|
+
INSERT##colour=purple
|
2
|
+
INTO##colour=purple
|
3
|
+
VALUES##colour=purple
|
4
|
+
CREATE TABLE##colour=red
|
5
|
+
CREATE SCHEMA##colour=red
|
6
|
+
SET SCHEMA##colour=yellow
|
7
|
+
DROP TABLE##colour=red
|
8
|
+
DROP SCHEMA##colour=red
|
9
|
+
char
|
10
|
+
integer
|
11
|
+
varchar
|
12
|
+
date
|
13
|
+
boolean
|
14
|
+
NOT NULL##colour=white
|
15
|
+
NULL##colour=white
|
16
|
+
(##colour=cyan
|
17
|
+
)##colour=cyan
|
18
|
+
);##colour=cyan
|
19
|
+
true##colour=blue
|
20
|
+
false##colour=yellow
|
data/lib/icersplicer.rb
CHANGED
@@ -12,28 +12,65 @@
|
|
12
12
|
module Icersplicer
|
13
13
|
|
14
14
|
module VERSION #:nodoc:
|
15
|
-
|
16
15
|
MAJOR = 0
|
17
|
-
MINOR =
|
18
|
-
TINY =
|
19
|
-
CODENAME = "
|
20
|
-
|
16
|
+
MINOR = 3
|
17
|
+
TINY = 6
|
18
|
+
CODENAME = "Ice Axe !"
|
21
19
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
22
|
-
|
23
20
|
end
|
24
21
|
|
25
22
|
@@nfile = 0
|
26
23
|
@@exp = nil
|
24
|
+
@@keywordsfile = "keywords.ice"
|
25
|
+
|
26
|
+
COLOURS = {"black" => 0,
|
27
|
+
"red" => 1,
|
28
|
+
"green" => 2,
|
29
|
+
"yellow" => 3,
|
30
|
+
"blue" => 4,
|
31
|
+
"purple" => 5,
|
32
|
+
"cyan" => 6,
|
33
|
+
"white" => 7}
|
34
|
+
|
35
|
+
def load_keywords(file)
|
36
|
+
keys = Array.new
|
37
|
+
unless Dir.exists?("#{Dir.home}/.icersplicer")
|
38
|
+
Dir.mkdir("#{Dir.home}/.icersplicer")
|
39
|
+
end
|
40
|
+
if File.exists?("#{Dir.home}/.icersplicer/#{file}")
|
41
|
+
File.open("#{Dir.home}/.icersplicer/#{file}") {|n|
|
42
|
+
n.each_line {|l|
|
43
|
+
keys << l.strip unless l.strip == ""
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return keys
|
47
|
+
else
|
48
|
+
return false
|
49
|
+
end
|
50
|
+
end
|
27
51
|
|
28
52
|
def text_highlighter(text)
|
29
|
-
keys =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
53
|
+
keys = load_keywords("#{@@keywordsfile}")
|
54
|
+
if keys == false
|
55
|
+
keys = ["Ln:", "SELECT", "CREATE TABLE", "UPDATE", "DELETE", "INSERT", "FROM", "OFFSET", "GROUP BY", "HAVING", "ORDER BY",
|
56
|
+
"ALTER USER", "ALTER TABLE", "COPY", "INTO", "VALUES", "DELIMITERS", "STDIN", "CREATE USER", "WITH", "USING",
|
57
|
+
"CREATE INDEX", "CONSTRAINT", "ALTER INDEX", "INTEGER", "CHAR", "CLOB", "VARCHAR", "STRING", "DEFAULT", "NULL", "NOT",
|
58
|
+
"RECORDS", "KEY", "PRIMARY", "FOREIGN", "BIGINT", "MERGE", "REMOTE", "DROP TABLE", "SET SCHEMA", "CREATE SCHEMA",
|
59
|
+
"ALTER SCHEMA", "ADD", "TABLE", "CREATE SEQUENCE", "ALTER SEQUENCE"]
|
60
|
+
end
|
34
61
|
cpicker = [2,3,4,1,7,5,6] # Just a selection of colours
|
35
62
|
keys.each {|n|
|
36
|
-
|
63
|
+
if n.split("##")[1] == nil
|
64
|
+
text.gsub!("#{n}", "\e[4;3#{cpicker[rand(cpicker.size)]}m#{n}\e[0m\ \e[0;32m".strip)
|
65
|
+
else
|
66
|
+
name = n.split("##")[1].split("=")[1]
|
67
|
+
#puts "Colour: #{name} #{COLOURS[name]}"
|
68
|
+
cnum = COLOURS[name].to_i
|
69
|
+
#puts "NVal: #{n}"
|
70
|
+
nval = n.split("##")[0]
|
71
|
+
text.gsub!("#{nval}", "\e[4;3#{cnum}m#{nval}\e[0m\ \e[0;32m".strip)
|
72
|
+
end
|
73
|
+
text.gsub!(" \e[0;32m", "\e[0;32m")
|
37
74
|
}
|
38
75
|
return text
|
39
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icersplicer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Hood
|
@@ -18,6 +18,7 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- bin/icersplicer
|
21
|
+
- examples/keywords.ice
|
21
22
|
- lib/icersplicer.rb
|
22
23
|
homepage: https://github.com/puppetpies/icersplicer
|
23
24
|
licenses:
|