pro 0.0.1 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +55 -32
- data/bin/pro +21 -0
- data/lib/pro.rb +75 -1
- data/lib/pro/version.rb +1 -1
- data/pro.gemspec +2 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ac15f737100200ff1b897182f49139736a8e876
|
4
|
+
data.tar.gz: 5ba1a872a3126ea296df0156936b393395920df6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ce52738f6186ed0d640c11761c76eeaf699d1c1993880fa0f1193897409775d32e7e37ff4f9447158c6f0d829623182d910e37bde8aaa8061b0dba5fe039ab3
|
7
|
+
data.tar.gz: 9fc044be29999b50daea1bf481899557c2503fa3f9d60e5b7c9a6ca6d816f33572d2780a6533ef456f1a2ff19757188d10f41b12ddd891f56b17977fb82f5913
|
data/README.md
CHANGED
@@ -1,28 +1,48 @@
|
|
1
1
|
# Pro
|
2
2
|
|
3
3
|
`pro` is a little utility to wrangle your git repositories.
|
4
|
-
|
5
|
-
|
4
|
+
It includes features like instantly cd'ing to your git repos and getting a
|
5
|
+
status overview. You can also run commands in every git repository.
|
6
6
|
|
7
|
-
##
|
7
|
+
## CD'ing to a project's repository
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Cd'ing to your projects is harder than it should be.
|
10
|
+
There are [many tools](https://github.com/rupa/z) that try and solve this
|
11
|
+
problem using frequency and recency.
|
12
|
+
Pro solves the problem by fuzzy searching only git repositories.
|
12
13
|
|
13
|
-
|
14
|
+
The `pd` command allows you to instantly CD to any git repo by fuzzy matching
|
15
|
+
its name.
|
16
|
+
You can install the `pd` tool (name configurable) by running `pro install`.
|
17
|
+
Once you have it you can do some pretty intense cd'ing:
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+

|
20
|
+
|
21
|
+
## State of the Repos Address
|
22
|
+
|
23
|
+
Oftentimes I find myself wondering which git repositories of mine still have
|
24
|
+
uncommitted changes or unpushed commits. I could find them all and run git
|
25
|
+
status but it would be nice to get a quick overview. `pro status` does this.
|
26
|
+
|
27
|
+

|
28
|
+
|
29
|
+
You can also run `pro status <repo>` to show the output of `git status` for a
|
30
|
+
certain repo.
|
31
|
+
|
32
|
+
## Run all the commands!
|
33
|
+
|
34
|
+
Wouldn't it be cool if you could run a command on all your repos and see a
|
35
|
+
summary of the output? Now you can!
|
36
|
+
|
37
|
+
You can do this with `pro run <command>`. If you don't pass a command it will
|
38
|
+
prompt you for one.
|
39
|
+
|
40
|
+
For example, searching all your repos for ruby files:
|
41
|
+
|
42
|
+

|
43
|
+
|
44
|
+
Notice that it double checks before running so you don't accidentally run `rm -rf *` on all
|
45
|
+
your projects.
|
26
46
|
|
27
47
|
## Installation
|
28
48
|
|
@@ -32,31 +52,34 @@ Pro is bundled as a Ruby gem. To install run:
|
|
32
52
|
|
33
53
|
## Usage
|
34
54
|
|
35
|
-
$ pro help
|
36
55
|
pro is a command to help you manage your git repositories.
|
37
56
|
|
38
|
-
|
39
|
-
|
40
|
-
|
57
|
+
Base Directory ==========
|
58
|
+
Pro works from a base directory for efficiency.
|
59
|
+
This is the folder that contains all your other git repositories;
|
41
60
|
they don't have to be at the base level, just somewhere down the tree.
|
42
61
|
|
43
|
-
|
44
|
-
a ~/.
|
62
|
+
To set the base directory set the PRO_BASE environment variable or make
|
63
|
+
a ~/.proBase file containing the path.
|
45
64
|
|
46
|
-
|
65
|
+
Commands ===============
|
47
66
|
pro search <query> - prints path of git repo that matches query.
|
48
|
-
pro
|
67
|
+
pro status - prints a list of all repos with uncommitted or unpushed changes.
|
68
|
+
pro status <name> - prints the output of 'git status' on the repo.
|
69
|
+
pro run - prompts for a command to run in all git repos.
|
70
|
+
pro run <command> - runs the given command in all git repos.
|
71
|
+
pro install - Install the pro cd command. cd to a directory by fuzzy git repo matching.
|
49
72
|
pro help - display help
|
50
73
|
|
51
|
-
|
52
|
-
|
53
|
-
you to cd to git repositories in your
|
74
|
+
CD Command ============
|
75
|
+
You can use the 'pro install' command to install a wrapper function that allows
|
76
|
+
you to cd to git repositories in your Pro Base wherever you are based on fuzzy matching.
|
54
77
|
|
55
|
-
|
78
|
+
Example:
|
56
79
|
|
57
|
-
~/
|
80
|
+
~/randomFolder/ $ pd pro
|
58
81
|
pro/ $ pwd
|
59
|
-
/
|
82
|
+
/Users/tristan/Box/Dev/Projects/pro
|
60
83
|
|
61
84
|
|
62
85
|
## Contributing
|
data/bin/pro
CHANGED
@@ -16,6 +16,10 @@ a ~/.proBase file containing the path.
|
|
16
16
|
|
17
17
|
Commands ===============
|
18
18
|
pro search <query> - prints path of git repo that matches query.
|
19
|
+
pro status - prints a list of all repos with uncommitted or unpushed changes.
|
20
|
+
pro status <name> - prints the output of 'git status' on the repo.
|
21
|
+
pro run - prompts for a command to run in all git repos.
|
22
|
+
pro run <command> - runs the given command in all git repos.
|
19
23
|
pro install - Install the pro cd command. cd to a directory by fuzzy git repo matching.
|
20
24
|
pro help - display help
|
21
25
|
|
@@ -38,6 +42,23 @@ when 'search'
|
|
38
42
|
puts Pro.find_repo(ARGV.first)
|
39
43
|
when 'install'
|
40
44
|
Pro.install_cd
|
45
|
+
when 'status'
|
46
|
+
if ARGV.first
|
47
|
+
path = Pro.find_repo(ARGV.first)
|
48
|
+
Dir.chdir(path) do
|
49
|
+
puts `git status`
|
50
|
+
end
|
51
|
+
else
|
52
|
+
Pro.status
|
53
|
+
end
|
54
|
+
when 'run'
|
55
|
+
unless ARGV.empty?
|
56
|
+
command = ARGV.join(" ")
|
57
|
+
else
|
58
|
+
print "Command: "
|
59
|
+
command = STDIN.gets.chomp
|
60
|
+
end
|
61
|
+
Pro.run_command(command)
|
41
62
|
when 'help'
|
42
63
|
puts HELP
|
43
64
|
end
|
data/lib/pro.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "pro/version"
|
2
2
|
require "find"
|
3
3
|
require "fuzzy_match"
|
4
|
+
require "colored"
|
4
5
|
|
5
6
|
SHELL_FUNCTION = <<END
|
6
7
|
# pro cd function
|
@@ -25,6 +26,9 @@ END
|
|
25
26
|
|
26
27
|
|
27
28
|
module Pro
|
29
|
+
DIRTY_MESSAGE = 'uncommitted'.red
|
30
|
+
UNPUSHED_MESSAGE = 'unpushed'.blue
|
31
|
+
JOIN_STRING = ' + '
|
28
32
|
# Finds the base directory where repos are kept
|
29
33
|
# Checks the environment variable PRO_BASE and the
|
30
34
|
# file .proBase
|
@@ -41,7 +45,10 @@ module Pro
|
|
41
45
|
end
|
42
46
|
base
|
43
47
|
end
|
44
|
-
|
48
|
+
|
49
|
+
# Searches for all the git repositories in the base directory.
|
50
|
+
# returns an array of [repo_name, path] pairs.
|
51
|
+
def self.repo_list
|
45
52
|
repos = []
|
46
53
|
Find.find(Pro.base_dir) do |path|
|
47
54
|
if FileTest.directory?(path)
|
@@ -53,9 +60,76 @@ module Pro
|
|
53
60
|
end
|
54
61
|
end
|
55
62
|
end
|
63
|
+
repos
|
64
|
+
end
|
65
|
+
|
66
|
+
# Fuzzy search for a git repository by name
|
67
|
+
# Returns the full path to the repository.
|
68
|
+
def self.find_repo(name)
|
69
|
+
repos = Pro.repo_list
|
56
70
|
match = FuzzyMatch.new(repos, :read => :first).find(name)
|
57
71
|
match[1] unless match.nil?
|
58
72
|
end
|
73
|
+
|
74
|
+
def self.run_command(command, confirm = true)
|
75
|
+
if confirm
|
76
|
+
print "Do you really want to run '#{command.bold}' on all repos [Y/n]? "
|
77
|
+
ans = STDIN.gets
|
78
|
+
return if ans.chomp != "Y"
|
79
|
+
end
|
80
|
+
repos = Pro.repo_list
|
81
|
+
repos.each do |r|
|
82
|
+
Dir.chdir(r[1])
|
83
|
+
result = `#{command}`
|
84
|
+
puts "#{r.first}:".bold.red
|
85
|
+
puts result
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# prints a status list showing repos with
|
90
|
+
# unpushed commits or uncommitted changes
|
91
|
+
def self.status
|
92
|
+
repos = Pro.repo_list
|
93
|
+
max_name = repos.map {|pair| pair.first.length}.max + 1
|
94
|
+
repos.each do |pair|
|
95
|
+
path = pair.last
|
96
|
+
status = Pro.repo_status(path)
|
97
|
+
next if status.empty?
|
98
|
+
name = format("%-#{max_name}s",pair.first).bold
|
99
|
+
puts "#{name} > #{status}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# returns a short status message for the repo
|
104
|
+
def self.repo_status(path)
|
105
|
+
messages = []
|
106
|
+
messages << DIRTY_MESSAGE unless Pro.repo_clean?(path)
|
107
|
+
messages << UNPUSHED_MESSAGE if Pro.repo_unpushed?(path)
|
108
|
+
messages.join(JOIN_STRING)
|
109
|
+
end
|
110
|
+
|
111
|
+
# Checks if there are any uncommitted changes
|
112
|
+
def self.repo_clean?(path)
|
113
|
+
status = ""
|
114
|
+
Dir.chdir(path) do
|
115
|
+
status = `git status 2>/dev/null`
|
116
|
+
end
|
117
|
+
return status.end_with?("(working directory clean)\n")
|
118
|
+
end
|
119
|
+
|
120
|
+
# Finds if there are any commits which have not been pushed to origin
|
121
|
+
def self.repo_unpushed?(path)
|
122
|
+
unpushed = ""
|
123
|
+
Dir.chdir(path) do
|
124
|
+
branch_ref = `/usr/bin/git symbolic-ref HEAD 2>/dev/null`
|
125
|
+
branch = branch_ref.chomp.split('/').last
|
126
|
+
unpushed = `git cherry -v origin/#{branch} 2>/dev/null`
|
127
|
+
end
|
128
|
+
return !(unpushed.empty?)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Adds a shell function to the shell config files that
|
132
|
+
# allows easy directory changing.
|
59
133
|
def self.install_cd
|
60
134
|
puts CD_INFO
|
61
135
|
print "Continue with installation (yN)? "
|
data/lib/pro/version.rb
CHANGED
data/pro.gemspec
CHANGED
@@ -9,12 +9,13 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Tristan Hume"]
|
10
10
|
spec.email = ["tris.hume@gmail.com"]
|
11
11
|
spec.description = %q{Lightweight git project tool.}
|
12
|
-
spec.summary = %q{Command line tool that allows you to quickly cd to git projects.}
|
12
|
+
spec.summary = %q{Command line tool that allows you to quickly cd to git projects and other handy things.}
|
13
13
|
spec.homepage = "http://github.com/trishume/pro"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
#spec.add_runtime_dependency 'commander','~> 4.1.2'
|
17
17
|
spec.add_runtime_dependency 'fuzzy_match'
|
18
|
+
spec.add_runtime_dependency 'colored'
|
18
19
|
|
19
20
|
spec.files = `git ls-files`.split($/)
|
20
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tristan Hume
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fuzzy_match
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colored
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,5 +106,6 @@ rubyforge_project:
|
|
92
106
|
rubygems_version: 2.0.3
|
93
107
|
signing_key:
|
94
108
|
specification_version: 4
|
95
|
-
summary: Command line tool that allows you to quickly cd to git projects
|
109
|
+
summary: Command line tool that allows you to quickly cd to git projects and other
|
110
|
+
handy things.
|
96
111
|
test_files: []
|