prj 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bba91d576fb7285a7207a033fc1962f244e3862bab830314adf407174d123d2a
4
+ data.tar.gz: 547c1a5940e7c938efbeeb8ec81611e3d16dc08382f8d4f8dfd323661aaed90e
5
+ SHA512:
6
+ metadata.gz: 995628c465b1768efb679b146b8dbd3bc28a916de98bcc99300b6a9da6608b9936c3a549615549c3d643884a6cfe551cb90ae9d657850cd9a4cbd80ada663a29
7
+ data.tar.gz: 7ab9c2f19c818ebd8fca562bdd450a0db6933bce61d5e3068e52ae0d7240c9640d4c96f2ef49527f6493053a503f7319b819ba50eee67d442da03f45c80c9470
data/Gemfile CHANGED
@@ -1,10 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- group :development do
4
- gem "rspec", "~> 2.11"
5
- gem "rake", "~> 0.9"
6
- gem 'simplecov', "~> 0.6", :require => false
7
- gem "rake-compiler"
8
- end
9
-
10
-
3
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,29 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prj (2.0.0)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
4
- diff-lcs (1.1.3)
5
- multi_json (1.3.7)
6
- rake (0.9.5)
7
- rake-compiler (0.8.3)
9
+ diff-lcs (1.5.0)
10
+ docile (1.4.0)
11
+ rake (13.0.6)
12
+ rake-compiler (1.2.5)
8
13
  rake
9
- rspec (2.12.0)
10
- rspec-core (~> 2.12.0)
11
- rspec-expectations (~> 2.12.0)
12
- rspec-mocks (~> 2.12.0)
13
- rspec-core (2.12.0)
14
- rspec-expectations (2.12.0)
15
- diff-lcs (~> 1.1.3)
16
- rspec-mocks (2.12.0)
17
- simplecov (0.7.1)
18
- multi_json (~> 1.0)
19
- simplecov-html (~> 0.7.1)
20
- simplecov-html (0.7.1)
14
+ rspec (3.12.0)
15
+ rspec-core (~> 3.12.0)
16
+ rspec-expectations (~> 3.12.0)
17
+ rspec-mocks (~> 3.12.0)
18
+ rspec-core (3.12.2)
19
+ rspec-support (~> 3.12.0)
20
+ rspec-expectations (3.12.3)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.12.0)
23
+ rspec-mocks (3.12.6)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.12.0)
26
+ rspec-support (3.12.1)
27
+ simplecov (0.22.0)
28
+ docile (~> 1.1)
29
+ simplecov-html (~> 0.11)
30
+ simplecov_json_formatter (~> 0.1)
31
+ simplecov-html (0.12.3)
32
+ simplecov_json_formatter (0.1.4)
21
33
 
22
34
  PLATFORMS
23
35
  ruby
24
36
 
25
37
  DEPENDENCIES
26
- rake (~> 0.9)
27
- rake-compiler
28
- rspec (~> 2.11)
29
- simplecov (~> 0.6)
38
+ prj!
39
+ rake (~> 13.0)
40
+ rake-compiler (~> 1.2)
41
+ rspec (~> 3.4)
42
+ simplecov (~> 0.22)
43
+
44
+ BUNDLED WITH
45
+ 2.4.10
data/README.md CHANGED
@@ -22,10 +22,16 @@ Installation & Configuration:
22
22
 
23
23
  ```gem install prj```
24
24
 
25
- ([RVM](http://rvm.io) users) check out [this blog post](http://blog.yarotsky.me/2012-12-15-faster-ruby-scripts-startup)
26
- 2. ([oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) users) Put [scripts/zsh/prj.plugin.zsh](https://raw.github.com/v-yarotsky/prj/master/scripts/zsh/prj.plugin.zsh) into ``~/.oh-my-zsh/custom/plugins/prj/prj.plugin.zsh``.
25
+ 2. Configure your shell:
26
+ * ([oh-my-zsh](https://github.com/robbyrussell/oh-my-zsh) users) Put [scripts/zsh/prj.plugin.zsh](https://raw.github.com/v-yarotsky/prj/master/scripts/zsh/prj.plugin.zsh) into ``~/.oh-my-zsh/custom/plugins/prj/prj.plugin.zsh``.
27
27
  Don't forget to enable the plugin in ~/.zshrc
28
28
 
29
+ * (bash users) Add the following snippet to your .bash_profile:
30
+
31
+ function p() {
32
+ builtin cd "$(prj $1)"
33
+ }
34
+
29
35
  3. Put a project root directory name into ~/.prj.yml, i.e:
30
36
  ```
31
37
  projects_root: ~/Projects
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ task :default => [:all_specs]
26
26
 
27
27
  require 'rake/extensiontask'
28
28
  Rake::ExtensionTask.new do |t|
29
- t.name = 'finder'
29
+ t.name = 'fast_traverse'
30
30
  t.ext_dir = 'ext/prj'
31
31
  t.lib_dir = 'lib/prj'
32
32
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 2.0.0
data/bin/prj CHANGED
@@ -13,4 +13,3 @@ Signal.trap("SIGINT") do
13
13
  end
14
14
 
15
15
  exit App.new(STDOUT, ARGV).run
16
-
data/ext/prj/extconf.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'mkmf'
2
2
 
3
- dir_config('finder')
4
- create_makefile('finder')
3
+ dir_config('fast_traverse')
4
+ create_makefile('fast_traverse')
@@ -0,0 +1,47 @@
1
+ #include <ruby.h>
2
+
3
+ #include <sys/types.h>
4
+ #include <sys/stat.h>
5
+ #include <fts.h>
6
+
7
+ void Init_fast_traverse();
8
+
9
+ VALUE prj_fast_traverse_traverse_m(VALUE self, VALUE projects_root, VALUE search_nested_repositories);
10
+
11
+ VALUE Prj, FastTraverse;
12
+
13
+ void Init_fast_traverse() {
14
+ Prj = rb_define_module("Prj");
15
+ FastTraverse = rb_define_module_under(Prj, "FastTraverse");
16
+ rb_define_singleton_method(FastTraverse, "traverse", prj_fast_traverse_traverse_m, 2);
17
+ }
18
+
19
+ VALUE prj_fast_traverse_traverse_m(VALUE self, VALUE projects_root, VALUE search_nested_repositories) {
20
+ FTS *fs = NULL;
21
+ FTSENT *child = NULL;
22
+ FTSENT *parent = NULL;
23
+ VALUE parent_path, child_name;
24
+
25
+ char *paths[] = { StringValueCStr(projects_root), NULL };
26
+ fs = fts_open(paths, FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT, NULL);
27
+
28
+ if (fs == NULL) {
29
+ return Qnil;
30
+ }
31
+
32
+ while ((parent = fts_read(fs)) != NULL) {
33
+ child = fts_children(fs, 0);
34
+ while(child != NULL) {
35
+ parent_path = rb_str_new(parent->fts_path, parent->fts_pathlen);
36
+ child_name = rb_str_new(child->fts_name, child->fts_namelen);
37
+ if (child->fts_info == FTS_D && rb_block_given_p() && RTEST(rb_yield_values(2, parent_path, child_name))) {
38
+ fts_set(fs, (RTEST(search_nested_repositories) ? child : parent), FTS_SKIP);
39
+ }
40
+ child = child->fts_link;
41
+ }
42
+ }
43
+
44
+ fts_close(fs);
45
+ return Qnil;
46
+ }
47
+
data/lib/prj/app.rb CHANGED
@@ -29,7 +29,7 @@ module Prj
29
29
 
30
30
  def config
31
31
  @config ||= begin
32
- config = File.exists?(self.class.config_path) ? YAML.load(File.read(self.class.config_path)) : {}
32
+ config = File.exist?(self.class.config_path) ? YAML.load(File.read(self.class.config_path)) : {}
33
33
  default_config.merge(config)
34
34
  end
35
35
  end
Binary file
data/lib/prj/finder.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'prj/fast_traverse'
2
+
3
+ module Prj
4
+
5
+ class Finder
6
+ def initialize(projects_root, options = {})
7
+ @root = File.expand_path(projects_root)
8
+ @vcs_directories = Array(options[:vcs_directories])
9
+ @search_nested_repositories = !!options[:search_nested_repositories]
10
+ @result = []
11
+ end
12
+
13
+ def find_project_directories
14
+ return @result unless @result.empty?
15
+ FastTraverse.traverse(@root, @search_nested_repositories) do |parent_path, child_name|
16
+ next false unless vcs_directory?(child_name)
17
+ @result << normalize_path(parent_path)
18
+ end
19
+ @result
20
+ end
21
+
22
+ private
23
+
24
+ def vcs_directory?(directory_name)
25
+ @vcs_directories.include? directory_name
26
+ end
27
+
28
+ def normalize_path(path)
29
+ path.sub(@root, "").chomp("/")
30
+ end
31
+ end
32
+
33
+ end
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,6 @@ if ENV['COVERAGE']
13
13
  end
14
14
 
15
15
  require 'rspec'
16
- require 'rspec/autorun'
17
16
 
18
17
  $:.unshift File.expand_path('../../lib', __FILE__)
19
18
 
metadata CHANGED
@@ -1,68 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prj
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.1
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vladimir Yarotsky
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2024-03-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :development
21
+ prerelease: false
16
22
  version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
23
  requirements:
19
- - - ~>
24
+ - - "~>"
20
25
  - !ruby/object:Gem::Version
21
- version: '2.11'
26
+ version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
22
29
  requirement: !ruby/object:Gem::Requirement
23
- none: false
24
30
  requirements:
25
- - - ~>
31
+ - - "~>"
26
32
  - !ruby/object:Gem::Version
27
- version: '2.11'
33
+ version: '13.0'
28
34
  type: :development
29
35
  prerelease: false
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
36
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
37
  requirements:
35
- - - ~>
38
+ - - "~>"
36
39
  - !ruby/object:Gem::Version
37
- version: '0.9'
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
38
43
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
44
  requirements:
41
- - - ~>
45
+ - - "~>"
42
46
  - !ruby/object:Gem::Version
43
- version: '0.9'
47
+ version: '1.2'
44
48
  type: :development
45
49
  prerelease: false
46
- - !ruby/object:Gem::Dependency
47
- name: simplecov
48
50
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
51
  requirements:
51
- - - ~>
52
+ - - "~>"
52
53
  - !ruby/object:Gem::Version
53
- version: '0.6'
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
54
57
  requirement: !ruby/object:Gem::Requirement
55
- none: false
56
58
  requirements:
57
- - - ~>
59
+ - - "~>"
58
60
  - !ruby/object:Gem::Version
59
- version: '0.6'
61
+ version: '0.22'
60
62
  type: :development
61
63
  prerelease: false
62
- description: ! ' Prj is an utility to quickly go to project directory using fuzzy
63
- matching
64
-
65
- '
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.22'
69
+ description: " Prj is an utility to quickly go to project directory using fuzzy
70
+ matching\n"
66
71
  email: vladimir.yarotksy@gmail.com
67
72
  executables:
68
73
  - prj
@@ -70,48 +75,46 @@ extensions:
70
75
  - ext/prj/extconf.rb
71
76
  extra_rdoc_files: []
72
77
  files:
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - VERSION
73
84
  - bin/prj
85
+ - ext/prj/extconf.rb
86
+ - ext/prj/fast_traverse.c
87
+ - lib/prj.rb
74
88
  - lib/prj/app.rb
75
89
  - lib/prj/dir_with_score.rb
90
+ - lib/prj/fast_traverse.bundle
76
91
  - lib/prj/filter.rb
77
- - lib/prj/finder.bundle
78
- - lib/prj.rb
79
- - ext/prj/extconf.rb
80
- - ext/prj/finder.c
92
+ - lib/prj/finder.rb
81
93
  - spec/acceptance/app_spec.rb
82
94
  - spec/lib/prj/filter_spec.rb
83
95
  - spec/lib/prj/finder_spec.rb
84
96
  - spec/spec_helper.rb
85
- - Gemfile
86
- - Gemfile.lock
87
- - Rakefile
88
- - LICENSE.txt
89
- - README.md
90
- - VERSION
91
97
  homepage: http://github.com/v-yarotsky/prj
92
98
  licenses:
93
99
  - MIT
94
- post_install_message:
100
+ metadata: {}
101
+ post_install_message:
95
102
  rdoc_options: []
96
103
  require_paths:
97
104
  - lib
98
105
  required_ruby_version: !ruby/object:Gem::Requirement
99
- none: false
100
106
  requirements:
101
- - - ! '>='
107
+ - - ">="
102
108
  - !ruby/object:Gem::Version
103
- version: '0'
109
+ version: 2.2.0
104
110
  required_rubygems_version: !ruby/object:Gem::Requirement
105
- none: false
106
111
  requirements:
107
- - - ! '>='
112
+ - - ">="
108
113
  - !ruby/object:Gem::Version
109
- version: 1.3.6
114
+ version: '0'
110
115
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 1.8.25
113
- signing_key:
116
+ rubygems_version: 3.4.10
117
+ signing_key:
114
118
  specification_version: 3
115
119
  summary: Fuzzy-matching project finder
116
120
  test_files: []
117
- has_rdoc:
data/ext/prj/finder.c DELETED
@@ -1,127 +0,0 @@
1
- #include <ruby.h>
2
-
3
- #include <sys/types.h>
4
- #include <sys/stat.h>
5
- #include <fts.h>
6
-
7
- void Init_finder();
8
-
9
- VALUE prj_finder_initialize_m(VALUE self, VALUE projectsRoot, VALUE options);
10
- VALUE expand_path(VALUE path);
11
-
12
- VALUE prj_finder_find_project_directories_m(VALUE self);
13
- VALUE prj_finder_traverse_projects_root(VALUE self, char *projectsRoot, int searchNestedRepositories, VALUE (*callback)(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child));
14
- VALUE prj_finder_collect_project(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child);
15
- char * prj_finder_normalize_path(char *path);
16
- VALUE prj_finder_is_vcs_dir(VALUE self, const char *dir);
17
-
18
- VALUE Prj, PrjFinder;
19
-
20
- void Init_finder() {
21
- Prj = rb_define_module("Prj");
22
- PrjFinder = rb_define_class_under(Prj, "Finder", rb_cObject);
23
- rb_define_method(PrjFinder, "initialize", prj_finder_initialize_m, 2);
24
- rb_define_method(PrjFinder, "find_project_directories", prj_finder_find_project_directories_m, 0);
25
- }
26
-
27
- VALUE prj_finder_initialize_m(VALUE self, VALUE projectsRoot, VALUE options) {
28
- VALUE expandedProjectsRoot, vcsDirectories, searchNestedRepositories;
29
- expandedProjectsRoot = expand_path(projectsRoot);
30
-
31
- vcsDirectories = rb_hash_aref(options, ID2SYM(rb_intern("vcs_directories")));
32
-
33
- if (!RTEST(vcsDirectories)) {
34
- vcsDirectories = rb_ary_new();
35
- }
36
-
37
- searchNestedRepositories = rb_hash_aref(options, ID2SYM(rb_intern("search_nested_repositories")));
38
-
39
- rb_iv_set(self, "@root", expandedProjectsRoot);
40
- rb_iv_set(self, "@vcs_directories", rb_check_array_type(vcsDirectories));
41
- rb_iv_set(self, "@search_nested_repositories", searchNestedRepositories);
42
- rb_iv_set(self, "@project_directories", rb_ary_new());
43
- return self;
44
- }
45
-
46
- VALUE expand_path(VALUE path) {
47
- VALUE file;
48
- file = rb_const_get(rb_cObject, rb_intern("File"));
49
- return rb_funcall(file, rb_intern("expand_path"), 1, rb_check_string_type(path));
50
- }
51
-
52
- VALUE prj_finder_find_project_directories_m(VALUE self) {
53
- VALUE result, root, searchNestedRepositories;
54
-
55
- result = rb_iv_get(self, "@project_directories");
56
- root = rb_iv_get(self, "@root");
57
- searchNestedRepositories = rb_iv_get(self, "@search_nested_repositories");
58
-
59
- if (RARRAY_LEN(result) == 0) {
60
- prj_finder_traverse_projects_root(self, StringValueCStr(root), RTEST(searchNestedRepositories), &prj_finder_collect_project);
61
- }
62
-
63
- return result;
64
- }
65
-
66
- VALUE prj_finder_traverse_projects_root(VALUE self, char *projectsRoot, int searchNestedRepositories, VALUE (*callback)(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child)) {
67
- FTS *fs = NULL;
68
- FTSENT *child = NULL;
69
- FTSENT *parent = NULL;
70
-
71
- char *paths[] = { projectsRoot, NULL };
72
- fs = fts_open(paths, FTS_COMFOLLOW | FTS_LOGICAL | FTS_NOSTAT, NULL);
73
-
74
- if (fs == NULL) {
75
- return Qnil;
76
- }
77
-
78
- while ((parent = fts_read(fs)) != NULL) {
79
- child = fts_children(fs, 0);
80
- while (child != NULL) {
81
- if (child->fts_info == FTS_D && RTEST(callback(self, fs, parent, child))) {
82
- fts_set(fs, (searchNestedRepositories ? child : parent), FTS_SKIP);
83
- }
84
- child = child->fts_link;
85
- }
86
- }
87
- fts_close(fs);
88
-
89
- return Qnil;
90
- }
91
-
92
- VALUE prj_finder_collect_project(VALUE self, const FTS *fs, const FTSENT *parent, const FTSENT *child) {
93
- VALUE root, result;
94
- char *prefixed, *unprefixed;
95
-
96
- if (!prj_finder_is_vcs_dir(self, child->fts_name)) {
97
- return Qfalse;
98
- }
99
-
100
- root = rb_iv_get(self, "@root");
101
- result = rb_iv_get(self, "@project_directories");
102
-
103
- prefixed = parent->fts_path;
104
- unprefixed = prefixed + RSTRING_LEN(root);
105
-
106
- rb_ary_push(result, rb_str_new2(prj_finder_normalize_path(unprefixed)));
107
- return Qtrue;
108
- }
109
-
110
- // strips unnecessary trailing / on linux
111
- char * prj_finder_normalize_path(char *path) {
112
- size_t path_length;
113
- path_length = strlen(path);
114
-
115
- if (path[path_length - 1] == '/') {
116
- path[path_length - 1] = '\0';
117
- }
118
-
119
- return path;
120
- }
121
-
122
- VALUE prj_finder_is_vcs_dir(VALUE self, const char *dir) {
123
- VALUE vcsDirectories;
124
- vcsDirectories = rb_iv_get(self, "@vcs_directories");
125
- return rb_funcall(vcsDirectories, rb_intern("include?"), 1, rb_str_new2(dir));
126
- }
127
-
Binary file