ackr 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,39 @@
1
+ Ackr
2
+ ================
3
+
4
+ Ackr is a very light grep/ack/rak replacement for lazy developers.
5
+
6
+ Description
7
+ -----------
8
+
9
+ TODO. Work in progress.
10
+
11
+ Run on linux. Maybe run on mac os. I guess it doesn't run on windows.
12
+
13
+ Install
14
+ -------------------------
15
+
16
+ gem install ackr
17
+
18
+ Usage
19
+ --------------------------
20
+
21
+ TODO. Work in progress.
22
+
23
+
24
+ Dependencies
25
+ --------------------------
26
+
27
+ * ruby >= 1.9.2
28
+
29
+ License
30
+ --------------------------
31
+
32
+ MIT
33
+
34
+
35
+ Questions and/or Comments
36
+ --------------------------
37
+
38
+ Feel free to email [Xavier Nayrac](mailto:xavier.nayrac@gmail.com)
39
+ with any questions.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ # todo: replace GEM by th gem name
4
+
5
+ require 'rake'
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc 'Test GEM'
9
+ task :default => :spec
10
+
11
+ desc 'Test GEM with rspec'
12
+ RSpec::Core::RakeTask.new(:spec) do |t|
13
+ t.rspec_opts = ['--color']
14
+ end
15
+
16
+ desc 'Check for code smells'
17
+ task :reek do
18
+ puts 'Checking for code smells...'
19
+ files = Dir.glob 'lib/**/*.rb'
20
+ # files.delete FILE_TO_EXCLUDE
21
+ args = files.join(' ')
22
+ sh "reek --quiet #{args} | ./reek.sed"
23
+ end
24
+
25
+ desc 'Build GEM & install it'
26
+ task :install do
27
+ sh "gem build GEM.gemspec"
28
+ f = FileList['GEM*gem'].to_a
29
+ sh "gem install #{f.first} --no-rdoc --no-ri"
30
+ end
31
+
32
+ desc 'Generate yard documentation for developpers'
33
+ task :doc do
34
+ exec 'yardoc --title "GEM Documentation" - NEWS COPYING VERSION'
35
+ end
data/TODO ADDED
@@ -0,0 +1,27 @@
1
+ Écrire le readme
2
+ write tests
3
+ use reek
4
+
5
+ ---------------------------
6
+
7
+ [ok]Dans tout les fichiers texte.
8
+ [ok]case insensitive
9
+ [ok]nom du fichier en couleur
10
+ [ok]terme de la recherche en gras
11
+ supprimer les espaces 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
14
+
15
+ ---------------------------
16
+
17
+ $ ackr /tel \d{10}/i
18
+
19
+
20
+ ---------------------------
21
+ fichier de config
22
+
23
+ ---------------------------
24
+ fuzzy search:
25
+ $ ackf abc
26
+ path/to/file
27
+ 00001| a123 b 2 568 c
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1
data/bin/ackr ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
5
+ $ACKR_PATH = File.expand_path(File.dirname(__FILE__)) + '/..'
6
+
7
+ require 'ackr'
8
+
9
+ if ARGV[0].nil?
10
+ puts "usage:
11
+
12
+ ackr search_string
13
+
14
+ ...OR...
15
+
16
+ ackr /regex/
17
+ "
18
+ else
19
+ Ackr::Finder.new(ARGV[0].dup).run
20
+ end
data/lib/ackr.rb ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'ackr/finder'
4
+ require 'ackr/colorizer'
5
+
6
+ module Ackr
7
+ # Method taken from: https://github.com/djberg96/ptools
8
+ # --
9
+ #
10
+ # Returns whether or not +file+ is a binary file. Note that this is
11
+ # not guaranteed to be 100% accurate. It performs a "best guess" based
12
+ # on a simple test of the first +File.blksize+ characters.
13
+ #
14
+ # Example:
15
+ #
16
+ # File.binary?('somefile.exe') # => true
17
+ # File.binary?('somefile.txt') # => false
18
+ #--
19
+ # Based on code originally provided by Ryan Davis (which, in turn, is
20
+ # based on Perl's -B switch).
21
+ #
22
+ def self.binary?(file)
23
+ s = (File.read(file, File.stat(file).blksize) || "").split(//)
24
+ ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rainbow'
4
+
5
+ module Ackr
6
+
7
+ # Methods to add terminal color commands into strings.
8
+ module Colorizer
9
+
10
+ # Public: Highlight a filename.
11
+ #
12
+ # string - The filename.
13
+ #
14
+ # Returns the String filename highlighted.
15
+ def self.for_file string
16
+ string.foreground(:blue).bright.underline
17
+ end
18
+
19
+ # Public: Highlight a matched file line.
20
+ #
21
+ # string - The line.
22
+ # search - The String search term.
23
+ #
24
+ # Returns the String line highlighted.
25
+ def self.for_line string, search
26
+ reg = Regexp.new(search, Regexp::IGNORECASE)
27
+ string.gsub(reg) do |exp|
28
+ exp.bright
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Ackr
4
+ class Finder
5
+
6
+ def initialize search_term
7
+ @search_term = search_term.downcase
8
+ end
9
+
10
+ def run
11
+ Dir.glob('**/*').each do |f|
12
+ next if File.directory?(f)
13
+ next if Ackr::binary?(f)
14
+ @file = f
15
+ search
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def search
22
+ results = search_into_file
23
+ unless results.empty?
24
+ puts Colorizer::for_file(@file)
25
+ results.each {|r| puts r}
26
+ puts ""
27
+ end
28
+ end
29
+
30
+ def search_into_file
31
+ result = []
32
+ File.readlines(@file).each_with_index do |line, i|
33
+ if line.downcase.include?(@search_term)
34
+ result << "#{'%4i' % i}| #{Colorizer::for_line(line, @search_term)}"
35
+ end
36
+ end
37
+ result
38
+ end
39
+
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ackr
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Xavier Nayrac
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rainbow
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.4
30
+ description: Ackr is a very light grep/ack/rak replacement for lazy developers.
31
+ email: xavier.nayrac@gmail.com
32
+ executables:
33
+ - ackr
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/ackr.rb
38
+ - lib/ackr/finder.rb
39
+ - lib/ackr/colorizer.rb
40
+ - bin/ackr
41
+ - VERSION
42
+ - README.markdown
43
+ - Rakefile
44
+ - TODO
45
+ homepage: https://github.com/lkdjiin/ackr
46
+ licenses:
47
+ - MIT
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: 1.9.2
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.25
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Ackr is a very light grep/ack/rak replacement for lazy developers.
70
+ test_files: []