rootee 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +6 -0
  3. data/README.md +64 -0
  4. data/Rakefile +17 -0
  5. data/bin/rootee +61 -0
  6. data/lib/rootee.rb +84 -0
  7. metadata +93 -0
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2012-10-12
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ bin/rootee
6
+ lib/rootee.rb
@@ -0,0 +1,64 @@
1
+ # openmeta.rb
2
+
3
+ * https://github.com/zhaocai/rootee
4
+
5
+
6
+ ## DESCRIPTION:
7
+
8
+ This short script tries to find project root path based on common source control directory structure and project related files.
9
+
10
+ It is not 100% accurately but works for most common cases.
11
+
12
+ ## INSTALLATION:
13
+
14
+ * `[sudo] gem install rootee`
15
+
16
+ ## USAGE EXAMPLE
17
+
18
+ ### 1. Quick Jump
19
+
20
+ To quickly jump to current project root in the shell. Add an alias to your zshrc or bshrc.
21
+ ```sh
22
+ alias r='cd `rootee`'
23
+ ```
24
+
25
+ ### 2. Launch Source Management Tool
26
+
27
+ To quickly launch Source Tree, for example.
28
+ ```sh
29
+ st () {
30
+ open -a SourceTree ${1:-`rootee`}
31
+ }
32
+ ```
33
+
34
+
35
+ ## KNOWN ISSUE:
36
+
37
+
38
+ ## DEVELOPERS:
39
+
40
+ After checking out the source, run:
41
+
42
+ $ rake newb
43
+
44
+ This task will install any missing dependencies, run the tests/specs,
45
+ and generate the RDoc.
46
+
47
+ ## LICENSE:
48
+
49
+ Copyright (c) 2013 Zhao Cai <caizhaoff@gmail.com>
50
+
51
+ This program is free software: you can redistribute it and/or modify it under
52
+ the terms of the GNU General Public License as published by the Free Software
53
+ Foundation, either version 3 of the License, or (at your option)
54
+ any later version.
55
+
56
+ This program is distributed in the hope that it will be useful, but WITHOUT
57
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
58
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
59
+
60
+ You should have received a copy of the GNU General Public License along with
61
+ this program. If not, see <http://www.gnu.org/licenses/>.
62
+
63
+
64
+
@@ -0,0 +1,17 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.plugin :gemspec
7
+ Hoe.plugin :bundler
8
+ Hoe.plugin :git
9
+
10
+ Hoe.spec 'rootee' do
11
+ version = "1.0.0"
12
+
13
+ developer('Zhao Cai', 'caizhaoff@gmail.com')
14
+ end
15
+
16
+
17
+ # vim: syntax=ruby
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
4
+ require 'optparse'
5
+ load "rootee"
6
+
7
+ def parse_opt()
8
+ options = {:from => Dir.getwd}
9
+
10
+ optparse = OptionParser.new do |opts|
11
+
12
+ opts.on('-f', "--from [PATH]",
13
+ "Search project root path from PATH") do |p|
14
+ options[:from] = t
15
+ end
16
+
17
+ opts.on('-h', '--help', 'Help Message') do
18
+ puts opts
19
+ exit
20
+ end
21
+ end
22
+
23
+ # parse and check mandatory options
24
+ begin
25
+ optparse.parse!
26
+ mandatory = []
27
+ missing = mandatory.select{ |param| options[param].nil? }
28
+ if not missing.empty?
29
+ puts "Missing options: #{missing.join(', ')}"
30
+ puts optparse
31
+ exit
32
+ end
33
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
34
+ puts $!.to_s
35
+ puts optparse
36
+ exit
37
+ end
38
+
39
+ return options
40
+ end
41
+
42
+
43
+
44
+
45
+ options = parse_opt()
46
+
47
+ rootee = Rootee.new()
48
+ is_find, root = rootee.find_root(options[:from])
49
+ if is_find
50
+ puts root
51
+ exit(0)
52
+ else
53
+ puts options[:from]
54
+ exit(-1)
55
+ end
56
+
57
+
58
+ # ~~ modeline ~~ [[[1 -------------------------------------------------------
59
+ # vim: set ft=ruby ts=2 sw=2 tw=78 fdm=syntax fmr=[[[,]]] fdl=1 :
60
+
61
+
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ # ============== = ===========================================================
4
+ # FileName : rootee
5
+ # Description : Project Root Path Finder
6
+ # Author : Zhao Cai <caizhaoff@gmail.com>
7
+ # HomePage : https://github.com/zhaocai/rootee
8
+ # Version : 0.1
9
+ # Date Created : Fri 22 Mar 2013 11:09:31 PM EDT
10
+ # Last Modified : Fri 22 Mar 2013 11:27:47 PM EDT
11
+ # Tag : [ ruby, project, path ]
12
+ # Copyright : © 2013 by Zhao Cai,
13
+ # Released under current GPL license.
14
+ # ============== = ===========================================================
15
+
16
+ require 'pathname'
17
+
18
+ class Rootee
19
+ VERSION = "1.0.0"
20
+
21
+ attr_accessor :marker
22
+ attr_accessor :end_path
23
+
24
+ def initialize(end_path=[], marker=[] )
25
+ @marker = [
26
+ {
27
+ :dir => ['.git/', '.svn/', '_darcs/', '.hg/', '.bzr/', 'nbproject/']
28
+ },
29
+ {
30
+ :file => ['./Makefile', './configure', './Rakefile',
31
+ './NAnt.build', './build.xml', './prj.el',
32
+ './pom.xml', './Gemfile', './Thorfile'],
33
+ },
34
+ {
35
+ :file => ['../project', './tags', './gtags'],
36
+ :dir => ['bin/', 'src/', 'include/', 'lib/', 'doc/', ],
37
+ },
38
+ ] if marker.empty?
39
+
40
+
41
+ home = Pathname.new(ENV['HOME'])
42
+ @end_path = end_path.empty? ? [ "/", home.realpath, ] : end_path
43
+ end
44
+
45
+
46
+ def find_root(start_path=Dir.getwd)
47
+ root = start_path
48
+ is_find = false
49
+
50
+ @marker.each { |m|
51
+ m.each { |type, filter|
52
+
53
+ Dir.chdir(start_path)
54
+ # upwards traverse
55
+ while ! end_path.include?(Dir.getwd)
56
+ glob_ret = Dir.glob(filter).select { |fn|
57
+ if type == :file
58
+ File.file?(fn)
59
+ elsif type == :dir
60
+ File.directory?(fn)
61
+ end
62
+ }
63
+
64
+ unless glob_ret.empty?
65
+ is_find = true
66
+ root = Dir.getwd
67
+ break
68
+ end
69
+ Dir.chdir('..')
70
+ end
71
+ }
72
+
73
+ break if is_find
74
+ }
75
+
76
+ Dir.chdir(start_path)
77
+ return is_find, root
78
+ end
79
+
80
+
81
+ end
82
+
83
+
84
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rootee
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zhao Cai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - !ruby/object:Gem::Dependency
31
+ name: hoe
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.5'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.5'
46
+ description: ! 'This short script tries to find project root path based on common
47
+ source control directory structure and project related files.
48
+
49
+
50
+ It is not 100% accurately but works for most common cases.'
51
+ email:
52
+ - caizhaoff@gmail.com
53
+ executables:
54
+ - rootee
55
+ extensions: []
56
+ extra_rdoc_files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - README.md
63
+ - Rakefile
64
+ - bin/rootee
65
+ - lib/rootee.rb
66
+ homepage: https://github.com/zhaocai/rootee
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --main
71
+ - README.md
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: rootee
88
+ rubygems_version: 1.8.24
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: This short script tries to find project root path based on common source
92
+ control directory structure and project related files
93
+ test_files: []