ackr 0.1.1 → 0.2
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.
- data/Gemfile +6 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +22 -0
- data/README.markdown +58 -5
- data/Rakefile +1 -0
- data/TODO +15 -13
- data/VERSION +1 -1
- data/bin/ackr +3 -1
- data/lib/ackr.rb +5 -0
- data/lib/ackr/colorizer.rb +5 -3
- data/lib/ackr/extensions/string.rb +27 -0
- data/lib/ackr/finder.rb +4 -0
- data/lib/ackr/formatter.rb +31 -0
- data/lib/ackr/search.rb +23 -4
- metadata +9 -4
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ackr (0.2)
|
5
|
+
rainbow (>= 1.1.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.4)
|
11
|
+
rainbow (1.1.4)
|
12
|
+
rake (10.0.4)
|
13
|
+
rspec (2.13.0)
|
14
|
+
rspec-core (~> 2.13.0)
|
15
|
+
rspec-expectations (~> 2.13.0)
|
16
|
+
rspec-mocks (~> 2.13.0)
|
17
|
+
rspec-core (2.13.1)
|
18
|
+
rspec-expectations (2.13.0)
|
19
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
+
rspec-mocks (2.13.1)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
ackr!
|
27
|
+
rake
|
28
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 lkdjiin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -1,14 +1,33 @@
|
|
1
|
-
Ackr
|
1
|
+
Ackr [](https://travis-ci.org/lkdjiin/ackr)
|
2
2
|
================
|
3
3
|
|
4
|
-
Ackr is a very
|
4
|
+
Ackr is a very small subset of grep/ack/rak, for **lazy developers**.
|
5
5
|
|
6
6
|
Description
|
7
7
|
-----------
|
8
8
|
|
9
|
-
|
9
|
+
Grep is a great tool. A very powerful tool. But most of the time, it is
|
10
|
+
too powerful for my needs. I can never remember its syntax nor its options.
|
10
11
|
|
11
|
-
|
12
|
+
Ack is great and powerful too. But here again it has so many options.
|
13
|
+
|
14
|
+
As a developer I have really simple needs. As a lazy developer I want the
|
15
|
+
most possible simple tool.
|
16
|
+
|
17
|
+
Here comes ackr:
|
18
|
+
|
19
|
+
* Ackr look for a search term into all text files, into all subfolders,
|
20
|
+
from the working directory
|
21
|
+
* A search term is either **a string** (in this case Ackr is *case insensitive*)
|
22
|
+
or **a regexp**
|
23
|
+
* Ackr has **no options**
|
24
|
+
* Ackr doesn't look into hidden folders/files
|
25
|
+
* Search term is displayed in bold font
|
26
|
+
|
27
|
+
It runs on linux. It maybe runs on mac os. I guess it won't run on windows.
|
28
|
+
|
29
|
+
And one more thing: ackr **is not a replacement to grep/ack**. If you
|
30
|
+
need grep power, just use grep!
|
12
31
|
|
13
32
|
Install
|
14
33
|
-------------------------
|
@@ -18,14 +37,48 @@ Install
|
|
18
37
|
Usage
|
19
38
|
--------------------------
|
20
39
|
|
21
|
-
|
40
|
+
To look for a string (case insensitive):
|
41
|
+
|
42
|
+
$ ackr fixme
|
43
|
+
lib/ackr/search.rb
|
44
|
+
8| # FIXME Separate behaviours: search / print
|
45
|
+
|
46
|
+
README.markdown
|
47
|
+
21| $ackr fixme
|
48
|
+
|
49
|
+
Using a regexp (same search as above):
|
50
|
+
|
51
|
+
$ ackr /fixme/i
|
52
|
+
|
53
|
+
More to come
|
54
|
+
--------------------------
|
55
|
+
|
56
|
+
Next version may include
|
22
57
|
|
58
|
+
* fuzzy search
|
59
|
+
* configuration
|
23
60
|
|
24
61
|
Dependencies
|
25
62
|
--------------------------
|
26
63
|
|
27
64
|
* ruby >= 1.9.2
|
28
65
|
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
73
|
+
|
74
|
+
### There is many other ways to contibute to ackr
|
75
|
+
|
76
|
+
1. Reports any bug
|
77
|
+
2. Give me ideas
|
78
|
+
3. Correct my poor english syntax
|
79
|
+
4. Blog about ackr
|
80
|
+
5. Tell ackr to your friends or colleagues
|
81
|
+
|
29
82
|
License
|
30
83
|
--------------------------
|
31
84
|
|
data/Rakefile
CHANGED
data/TODO
CHANGED
@@ -1,27 +1,29 @@
|
|
1
|
-
Écrire le readme
|
2
|
-
travis-ci
|
3
1
|
|
4
|
-
|
2
|
+
[ok]supprimer les espaces/tab avant
|
3
|
+
[ok]$ ackr /tel \d{10}/i
|
4
|
+
[ok]terme de la regex en gras dans le terminal
|
5
|
+
[ok]Bug invalid byte sequence
|
5
6
|
|
6
|
-
|
7
|
-
[ok]case insensitive
|
8
|
-
[ok]nom du fichier en couleur
|
9
|
-
[ok]terme de la recherche en gras
|
10
|
-
[ok]ne pas chercher dans les dossiers/fichiers cachés
|
11
|
-
supprimer les espaces/tab avant/après
|
12
|
-
1|.le point signale que un (ou des) espaces ont été supprimés
|
13
|
-
une ligne sur le terminal fait 80 char max
|
7
|
+
Exclure dossier temp/ tmp/ et d'autres
|
14
8
|
|
15
9
|
---------------------------
|
10
|
+
fichier de config
|
16
11
|
|
17
|
-
|
12
|
+
---------------------------
|
13
|
+
Site web
|
18
14
|
|
15
|
+
---------------------------
|
16
|
+
Écrire à rainbow owner pour lui dire que j'utilise son truc
|
17
|
+
dans ce projet.
|
19
18
|
|
20
19
|
---------------------------
|
21
|
-
|
20
|
+
Améliorer les perfs
|
22
21
|
|
23
22
|
---------------------------
|
24
23
|
fuzzy search:
|
25
24
|
$ ackf abc
|
26
25
|
path/to/file
|
27
26
|
00001| a123 b 2 568 c
|
27
|
+
|
28
|
+
---------------------------
|
29
|
+
une ligne sur le terminal fait 80 char max
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2
|
data/bin/ackr
CHANGED
data/lib/ackr.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'ackr/extensions/string'
|
3
4
|
require 'ackr/search'
|
4
5
|
require 'ackr/colorizer'
|
5
6
|
require 'ackr/finder'
|
7
|
+
require 'ackr/formatter'
|
6
8
|
|
7
9
|
module Ackr
|
10
|
+
|
11
|
+
EXCLUDE_DIRS = %w(blib CVS _darcs RCS SCCS pkg tmp temp log)
|
12
|
+
|
8
13
|
# Method taken from: https://github.com/djberg96/ptools
|
9
14
|
# --
|
10
15
|
#
|
data/lib/ackr/colorizer.rb
CHANGED
@@ -23,9 +23,11 @@ module Ackr
|
|
23
23
|
#
|
24
24
|
# Returns the String line highlighted.
|
25
25
|
def self.for_line string, search
|
26
|
-
|
27
|
-
|
28
|
-
exp.bright
|
26
|
+
search = Regexp.new(search, Regexp::IGNORECASE) if search.is_a?(String)
|
27
|
+
begin
|
28
|
+
string.gsub(search) {|exp| exp.bright }
|
29
|
+
rescue Exception => ex
|
30
|
+
puts "Error ".background(:red) + ex.message
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
class String
|
4
|
+
|
5
|
+
# Public: Transform itself in a Regexp.
|
6
|
+
#
|
7
|
+
# Returns a Regexp if successful, nil otherwise.
|
8
|
+
# ---
|
9
|
+
# Credit to Josh Cheek: http://www.ruby-forum.com/topic/193809
|
10
|
+
#
|
11
|
+
# Note: there is also a gem:
|
12
|
+
# https://github.com/seamusabshere/to_regexp
|
13
|
+
# Could be useful if I later want to parse things like
|
14
|
+
# $ ackr %r{regexp}
|
15
|
+
# or if bugs are discovered in the following code.
|
16
|
+
def to_regexp
|
17
|
+
return nil unless self.strip.match(/\A\/(.*)\/(.*)\Z/mx)
|
18
|
+
regexp , flags = $1 , $2
|
19
|
+
return nil if !regexp || flags =~ /[^xim]/m
|
20
|
+
|
21
|
+
x = /x/.match(flags) && Regexp::EXTENDED
|
22
|
+
i = /i/.match(flags) && Regexp::IGNORECASE
|
23
|
+
m = /m/.match(flags) && Regexp::MULTILINE
|
24
|
+
|
25
|
+
Regexp.new regexp , [x,i,m].inject(0){|a,f| f ? a+f : a }
|
26
|
+
end
|
27
|
+
end
|
data/lib/ackr/finder.rb
CHANGED
@@ -16,6 +16,10 @@ module Ackr
|
|
16
16
|
def self.all_files
|
17
17
|
Dir.glob('**/*').each do |file|
|
18
18
|
next if (File.directory?(file) || Ackr::binary?(file))
|
19
|
+
next if EXCLUDE_DIRS.any? do |dir|
|
20
|
+
file.start_with?(dir + File::Separator) ||
|
21
|
+
file.include?(File::Separator + dir + File::Separator)
|
22
|
+
end
|
19
23
|
yield(file)
|
20
24
|
end
|
21
25
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Ackr
|
4
|
+
|
5
|
+
# Format strings to be displayed on terminal.
|
6
|
+
class Formatter
|
7
|
+
|
8
|
+
# Public:
|
9
|
+
#
|
10
|
+
# search_term - The String or Regexp to look for.
|
11
|
+
def initialize search_term
|
12
|
+
@search_term = search_term
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: format a line with matched term(s).
|
16
|
+
#
|
17
|
+
# line - The String line to be displayed.
|
18
|
+
# num - The Integer number of the line (in base 1).
|
19
|
+
#
|
20
|
+
# Returns a formatted String.
|
21
|
+
def line line, num
|
22
|
+
begin
|
23
|
+
line.strip!
|
24
|
+
rescue Exception => ex
|
25
|
+
puts "Error ".background(:red) + ex.message
|
26
|
+
end
|
27
|
+
"#{'%4i' % num}| #{Colorizer::for_line(line, @search_term)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/ackr/search.rb
CHANGED
@@ -11,8 +11,17 @@ module Ackr
|
|
11
11
|
# Public:
|
12
12
|
#
|
13
13
|
# search_term - The String to look for.
|
14
|
+
# This param could be a 'real' string or a String
|
15
|
+
# representing a regexp. If the string looks like
|
16
|
+
# a regexp, it will be treated like a regexp.
|
17
|
+
#
|
18
|
+
# Examples:
|
19
|
+
# Search.new("abc")
|
20
|
+
# Search.new("/abc/i")
|
14
21
|
def initialize search_term
|
15
|
-
@search_term = search_term.
|
22
|
+
@search_term = search_term.to_regexp
|
23
|
+
@search_term = search_term.downcase if @search_term.nil?
|
24
|
+
@format = Formatter.new @search_term
|
16
25
|
end
|
17
26
|
|
18
27
|
# Public: Launch the search.
|
@@ -37,12 +46,22 @@ module Ackr
|
|
37
46
|
def search_into_file
|
38
47
|
result = []
|
39
48
|
File.readlines(@file).each_with_index do |line, idx|
|
40
|
-
|
41
|
-
|
42
|
-
end
|
49
|
+
found = search_into_line(line)
|
50
|
+
result << @format.line(line, idx + 1) if found
|
43
51
|
end
|
44
52
|
result
|
45
53
|
end
|
46
54
|
|
55
|
+
def search_into_line line
|
56
|
+
begin
|
57
|
+
if @search_term.is_a?(String)
|
58
|
+
line.downcase.include?(@search_term)
|
59
|
+
else
|
60
|
+
@search_term =~ line
|
61
|
+
end
|
62
|
+
rescue #Exception => ex
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
47
66
|
end
|
48
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ackr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rainbow
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.1.4
|
30
|
-
description: Ackr is a very
|
30
|
+
description: Ackr is a very small subset of grep/ack/rak, for lazy developers
|
31
31
|
email: xavier.nayrac@gmail.com
|
32
32
|
executables:
|
33
33
|
- ackr
|
@@ -37,12 +37,17 @@ files:
|
|
37
37
|
- lib/ackr.rb
|
38
38
|
- lib/ackr/finder.rb
|
39
39
|
- lib/ackr/search.rb
|
40
|
+
- lib/ackr/formatter.rb
|
41
|
+
- lib/ackr/extensions/string.rb
|
40
42
|
- lib/ackr/colorizer.rb
|
41
43
|
- bin/ackr
|
44
|
+
- LICENSE.txt
|
42
45
|
- VERSION
|
43
46
|
- README.markdown
|
47
|
+
- Gemfile
|
44
48
|
- Rakefile
|
45
49
|
- TODO
|
50
|
+
- Gemfile.lock
|
46
51
|
homepage: https://github.com/lkdjiin/ackr
|
47
52
|
licenses:
|
48
53
|
- MIT
|
@@ -67,5 +72,5 @@ rubyforge_project:
|
|
67
72
|
rubygems_version: 1.8.25
|
68
73
|
signing_key:
|
69
74
|
specification_version: 3
|
70
|
-
summary: Ackr is a very
|
75
|
+
summary: Ackr is a very small subset of grep/ack/rak, for lazy developers
|
71
76
|
test_files: []
|