gpr 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -14
- data/bin/gpr +2 -2
- data/gpr.gemspec +1 -0
- data/lib/gpr.rb +2 -0
- data/lib/gpr/cli.rb +31 -14
- data/lib/gpr/git_helper.rb +6 -2
- data/lib/gpr/version.rb +1 -1
- data/lib/graph_drawer.rb +2 -2
- data/lib/graph_drawer/data.rb +9 -2
- data/lib/interactive_filter.rb +25 -0
- data/lib/interactive_filter/input.rb +27 -0
- data/lib/interactive_filter/interface.rb +120 -0
- data/lib/table_builder.rb +4 -4
- data/zsh/gpr.zsh +4 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80d2d92c3f8db42725dddeb4d0b9b260afe8a8ba
|
4
|
+
data.tar.gz: b0b7c3932b6a09afea0b4225aa69d377f2871c2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0717eec796c4a585f41c2f43c1dd9b248763a63e79657343582a7e4da00bcdb784de28b9aef82e6dfc03eb900f3e7b355e302a7d030684e7b8a69351e0345e4
|
7
|
+
data.tar.gz: 105a7e363d6ef9c09fe5a1d30e1790e3dd7274fa0d7302730d30618446c950692551f478e5d17a32f7645e48323fdca090368878a16518739713edce5e7c70c3
|
data/README.md
CHANGED
@@ -12,14 +12,6 @@ For example, all repositories are cloned to `$HOME/.gpr/<host>/<user>/<repositor
|
|
12
12
|
|
13
13
|
It is possible to centrally manage of the all repositories.
|
14
14
|
|
15
|
-
## Work with peco
|
16
|
-
|
17
|
-
Gpr provides a list of directories of all registered repositories.
|
18
|
-
|
19
|
-
Therefore, it is powerful when combined with [peco](https://github.com/peco/peco).
|
20
|
-
|
21
|
-
![with\_peco](https://raw.github.com/wiki/kaihar4/gpr/images/with_peco.gif)
|
22
|
-
|
23
15
|
## Installation
|
24
16
|
|
25
17
|
```sh
|
@@ -32,7 +24,7 @@ $ gem install gpr
|
|
32
24
|
$ gpr help
|
33
25
|
```
|
34
26
|
|
35
|
-
###
|
27
|
+
### Register a git repository into Gpr directory
|
36
28
|
|
37
29
|
Just clone a git repository into `$HOME/.gpr/<host>/<user>/<repository>`.
|
38
30
|
|
@@ -40,7 +32,7 @@ Just clone a git repository into `$HOME/.gpr/<host>/<user>/<repository>`.
|
|
40
32
|
$ gpr get <repository url>
|
41
33
|
```
|
42
34
|
|
43
|
-
###
|
35
|
+
### Register all public repositories of the specified user
|
44
36
|
|
45
37
|
You can specify host only `github.com` or `bitbucket.org`.
|
46
38
|
|
@@ -62,7 +54,19 @@ $ gpr list --paths
|
|
62
54
|
|
63
55
|
![list\_paths](https://raw.github.com/wiki/kaihar4/gpr/images/list_paths.png)
|
64
56
|
|
65
|
-
###
|
57
|
+
### Select a repository using the interactive interface
|
58
|
+
|
59
|
+
```sh
|
60
|
+
$ gpr select
|
61
|
+
```
|
62
|
+
|
63
|
+
Possible use as this.
|
64
|
+
|
65
|
+
![select](https://raw.github.com/wiki/kaihar4/gpr/images/select.gif)
|
66
|
+
|
67
|
+
Other benefits is [here](#convenient-aliases).
|
68
|
+
|
69
|
+
### Show your contributions of registered repositories
|
66
70
|
|
67
71
|
Display in graph format.
|
68
72
|
|
@@ -109,7 +113,7 @@ $ gpr update
|
|
109
113
|
### Fetch all registered repositories
|
110
114
|
|
111
115
|
```sh
|
112
|
-
$ gpr fetch <
|
116
|
+
$ gpr fetch <remote repository>
|
113
117
|
```
|
114
118
|
|
115
119
|
If you run for short, it means `gpr fetch origin`.
|
@@ -118,13 +122,15 @@ If you run for short, it means `gpr fetch origin`.
|
|
118
122
|
$ gpr fetch
|
119
123
|
```
|
120
124
|
|
121
|
-
##
|
125
|
+
## Configuration
|
126
|
+
|
127
|
+
### Change the directory to be cloned
|
122
128
|
|
123
129
|
```sh
|
124
130
|
$ export GPR_ROOT=$HOME/develop
|
125
131
|
```
|
126
132
|
|
127
|
-
|
133
|
+
### Install the zsh completion
|
128
134
|
|
129
135
|
```sh
|
130
136
|
$ gpr get https://github.com/kaihar4/gpr.git
|
@@ -132,3 +138,16 @@ $ cd $HOME/.gpr/github.com/kaihar4/gpr
|
|
132
138
|
$ rake zsh:install
|
133
139
|
$ source ~/.zshrc
|
134
140
|
```
|
141
|
+
|
142
|
+
### Convenient aliases
|
143
|
+
|
144
|
+
```sh
|
145
|
+
# Change Directory to a directory that you specify
|
146
|
+
alias gcd='cd $(gpr select)'
|
147
|
+
# Remove a directory that you specify
|
148
|
+
alias grm='rm -rf $(gpr select)'
|
149
|
+
# Show your contributions of a directory that you specify
|
150
|
+
alias gcontrib='gpr contrib $(gpr select)'
|
151
|
+
# Fetch a repository of a directory that you specify
|
152
|
+
alias gfetch='gpr fetch $(gpr select)'
|
153
|
+
```
|
data/bin/gpr
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
require 'gpr'
|
4
4
|
|
5
|
-
|
5
|
+
if FileTest.exist?("#{Gpr::DB_PATH}/gpr.db")
|
6
6
|
Groonga::Database.open("#{Gpr::DB_PATH}/gpr.db")
|
7
|
-
|
7
|
+
else
|
8
8
|
FileUtils.mkdir_p(Gpr::DB_PATH)
|
9
9
|
Groonga::Context.default_options = { encoding: :utf8 }
|
10
10
|
Groonga::Database.create(path: "#{Gpr::DB_PATH}/gpr.db")
|
data/gpr.gemspec
CHANGED
data/lib/gpr.rb
CHANGED
@@ -5,10 +5,12 @@ require 'find'
|
|
5
5
|
|
6
6
|
require 'thor'
|
7
7
|
require 'groonga'
|
8
|
+
require 'curses'
|
8
9
|
|
9
10
|
require 'colorize'
|
10
11
|
require 'table_builder'
|
11
12
|
require 'graph_drawer'
|
13
|
+
require 'interactive_filter'
|
12
14
|
require 'gpr/version'
|
13
15
|
require 'gpr/api_helper'
|
14
16
|
require 'gpr/git_helper'
|
data/lib/gpr/cli.rb
CHANGED
@@ -53,28 +53,37 @@ module Gpr
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
desc '
|
56
|
+
desc 'select', 'Select a repository using the interactive interface'
|
57
|
+
def select
|
58
|
+
repositories = get_repositories
|
59
|
+
puts InteractiveFilter.filtering(repositories)
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'contrib', 'Show your contributions of registered repositories'
|
57
63
|
def contrib(path = nil)
|
58
|
-
|
59
|
-
|
64
|
+
git_user = File.open("#{ENV['HOME']}/.gitconfig", 'r') do |f|
|
65
|
+
body = f.read
|
66
|
+
body.match(/name\s+=\s+(.+)/)[1]
|
67
|
+
end
|
68
|
+
user = git_user || ENV['USER']
|
60
69
|
|
70
|
+
if path.nil?
|
61
71
|
repositories = get_repositories
|
62
|
-
repositories.
|
63
|
-
|
72
|
+
dates = repositories.each_with_object([]) do |repository, ary|
|
73
|
+
ary.concat(GitHelper.log_by_date(repository, user))
|
64
74
|
end
|
65
75
|
|
66
76
|
else
|
67
|
-
dates = GitHelper.log_by_date(path)
|
77
|
+
dates = GitHelper.log_by_date(path, user)
|
68
78
|
end
|
69
79
|
|
70
80
|
first_date = Time.parse(dates.sort.first)
|
71
81
|
diff = ((Time.now - first_date).to_i / 86400) + 1
|
72
82
|
|
73
83
|
# Initialize a hash
|
74
|
-
commit_counts = {}
|
75
|
-
diff.times.with_index do |index|
|
84
|
+
commit_counts = diff.times.each_with_object({}) do |index, hash|
|
76
85
|
date = Time.at(first_date + (86400 * index)).strftime('%Y-%m-%d')
|
77
|
-
|
86
|
+
hash[date] = 0
|
78
87
|
end
|
79
88
|
|
80
89
|
# Count commits
|
@@ -123,14 +132,22 @@ module Gpr
|
|
123
132
|
end
|
124
133
|
|
125
134
|
desc 'fetch', 'Fetch the registered repositories'
|
126
|
-
def fetch(remote = 'origin', branch = nil)
|
127
|
-
|
128
|
-
|
129
|
-
|
135
|
+
def fetch(remote = 'origin', branch = nil, path = nil)
|
136
|
+
if path.nil?
|
137
|
+
repositories = get_repositories
|
138
|
+
repositories.each do |repository|
|
139
|
+
repo_info = parse_repository(repository)
|
140
|
+
|
141
|
+
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
142
|
+
|
143
|
+
GitHelper.fetch(repository, remote, branch)
|
144
|
+
end
|
145
|
+
else
|
146
|
+
repo_info = parse_repository(path)
|
130
147
|
|
131
148
|
puts "#{repo_info[:host].color(:yellow)} - #{repo_info[:repository].color(:blue)}"
|
132
149
|
|
133
|
-
GitHelper.fetch(
|
150
|
+
GitHelper.fetch(path, remote, branch)
|
134
151
|
end
|
135
152
|
end
|
136
153
|
|
data/lib/gpr/git_helper.rb
CHANGED
@@ -39,9 +39,13 @@ module Gpr
|
|
39
39
|
result
|
40
40
|
end
|
41
41
|
|
42
|
-
def log_by_date(path)
|
42
|
+
def log_by_date(path, user = nil)
|
43
43
|
Dir.chdir(path)
|
44
|
-
|
44
|
+
if user.nil?
|
45
|
+
`git log --date=short --pretty=format:"%cd"`.split("\n")
|
46
|
+
else
|
47
|
+
`git log --author=#{user} --date=short --pretty=format:"%cd"`.split("\n")
|
48
|
+
end
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
data/lib/gpr/version.rb
CHANGED
data/lib/graph_drawer.rb
CHANGED
data/lib/graph_drawer/data.rb
CHANGED
@@ -23,8 +23,15 @@ module GraphDrawer
|
|
23
23
|
:blue
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
26
|
+
if @value.zero?
|
27
|
+
draw_str = "#{@item}|"
|
28
|
+
else
|
29
|
+
bar = ' ' * (@value - 1)
|
30
|
+
data_label = @value.to_s.color(:black)
|
31
|
+
draw_str = "#{@item}|#{(bar + data_label).bg_color(color)}"
|
32
|
+
end
|
33
|
+
|
34
|
+
draw_str
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'interactive_filter/input'
|
2
|
+
require 'interactive_filter/interface'
|
3
|
+
|
4
|
+
module InteractiveFilter
|
5
|
+
def self.filtering(repositories)
|
6
|
+
name = caller.last.match(/.+\/(.+?)(:|\.)/)[1].capitalize
|
7
|
+
|
8
|
+
isatty = STDOUT.isatty
|
9
|
+
|
10
|
+
unless isatty
|
11
|
+
stdout_old = STDOUT.dup
|
12
|
+
STDOUT.reopen('/dev/tty')
|
13
|
+
end
|
14
|
+
|
15
|
+
ifilter = Interface.new(name, repositories)
|
16
|
+
result = ifilter.grep
|
17
|
+
|
18
|
+
unless isatty
|
19
|
+
STDOUT.flush
|
20
|
+
STDOUT.reopen(stdout_old)
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module InteractiveFilter
|
2
|
+
class Input
|
3
|
+
attr_accessor :text
|
4
|
+
|
5
|
+
def initialize(text = '')
|
6
|
+
@text = text
|
7
|
+
end
|
8
|
+
|
9
|
+
def <<(text)
|
10
|
+
@text << text
|
11
|
+
end
|
12
|
+
|
13
|
+
def backspace!
|
14
|
+
@text.chop!
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
@text
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_regex
|
22
|
+
/#{@text}/
|
23
|
+
rescue
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
module InteractiveFilter
|
2
|
+
class Interface
|
3
|
+
def initialize(name, array)
|
4
|
+
@prompt = "#{name}> "
|
5
|
+
@targets = array
|
6
|
+
|
7
|
+
@input = Input.new
|
8
|
+
@cursor_position = 1
|
9
|
+
|
10
|
+
Curses.init_screen
|
11
|
+
Curses.crmode
|
12
|
+
Curses.noecho
|
13
|
+
@window = Curses::Window.new(Curses.lines, Curses.cols, 0, 0)
|
14
|
+
@window.keypad(true)
|
15
|
+
|
16
|
+
# Initialize a window
|
17
|
+
@outputs = []
|
18
|
+
@window.clear
|
19
|
+
reset_cursor_position
|
20
|
+
|
21
|
+
output_line(@prompt)
|
22
|
+
output_choises
|
23
|
+
reset_cursor_position
|
24
|
+
end
|
25
|
+
|
26
|
+
def grep
|
27
|
+
loop do
|
28
|
+
key = @window.getch
|
29
|
+
keycode = get_keycode(key)
|
30
|
+
|
31
|
+
if key.class == String
|
32
|
+
@input << key
|
33
|
+
|
34
|
+
# <BS>
|
35
|
+
elsif key == 127
|
36
|
+
@input.backspace!
|
37
|
+
|
38
|
+
# <CR>
|
39
|
+
elsif keycode == :KEY_CTRL_J
|
40
|
+
if @outputs.size >= @cursor_position && @cursor_position >= 1
|
41
|
+
break
|
42
|
+
else
|
43
|
+
next
|
44
|
+
end
|
45
|
+
|
46
|
+
elsif keycode == :KEY_DOWN
|
47
|
+
down_cursor_position if @outputs.size > @cursor_position
|
48
|
+
next
|
49
|
+
|
50
|
+
elsif keycode == :KEY_UP
|
51
|
+
up_cursor_position if @cursor_position > 1
|
52
|
+
next
|
53
|
+
|
54
|
+
# Ignore other keys
|
55
|
+
else
|
56
|
+
next
|
57
|
+
end
|
58
|
+
|
59
|
+
# Initialize a window
|
60
|
+
@outputs = []
|
61
|
+
@window.clear
|
62
|
+
reset_cursor_position
|
63
|
+
|
64
|
+
output_line(@prompt + @input.to_s)
|
65
|
+
output_choises
|
66
|
+
reset_cursor_position
|
67
|
+
end
|
68
|
+
|
69
|
+
Curses.close_screen
|
70
|
+
return @outputs[@cursor_position - 1]
|
71
|
+
|
72
|
+
# <C-c>
|
73
|
+
rescue Interrupt
|
74
|
+
Curses.close_screen
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def get_keycode(key)
|
80
|
+
Curses.constants.select do |name|
|
81
|
+
/^KEY/ =~ name && Curses.const_get(name) == key
|
82
|
+
end.first
|
83
|
+
end
|
84
|
+
|
85
|
+
def output_choises
|
86
|
+
# Filtering
|
87
|
+
@targets.each do |target|
|
88
|
+
regex = @input.to_regex
|
89
|
+
|
90
|
+
if !regex.nil? && regex =~ target
|
91
|
+
@outputs << target
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
@outputs.each { |output| output_line(output) }
|
96
|
+
end
|
97
|
+
|
98
|
+
def output_line(word)
|
99
|
+
@window.setpos(@cursor_position - 1, 0)
|
100
|
+
@cursor_position += 1
|
101
|
+
|
102
|
+
@window << word
|
103
|
+
end
|
104
|
+
|
105
|
+
def up_cursor_position
|
106
|
+
@window.setpos(@cursor_position - 1, 0)
|
107
|
+
@cursor_position -= 1
|
108
|
+
end
|
109
|
+
|
110
|
+
def down_cursor_position
|
111
|
+
@window.setpos(@cursor_position + 1, 0)
|
112
|
+
@cursor_position += 1
|
113
|
+
end
|
114
|
+
|
115
|
+
def reset_cursor_position
|
116
|
+
@window.setpos(1, 0)
|
117
|
+
@cursor_position = 1
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
data/lib/table_builder.rb
CHANGED
@@ -4,15 +4,15 @@ require 'table_builder/column_validator'
|
|
4
4
|
require 'table_builder/column'
|
5
5
|
|
6
6
|
module TableBuilder
|
7
|
-
def table(min_column_size = 10
|
7
|
+
def table(min_column_size = 10)
|
8
8
|
@table = Table.new(min_column_size)
|
9
|
-
|
9
|
+
yield
|
10
10
|
@table.to_s
|
11
11
|
end
|
12
12
|
|
13
|
-
def row
|
13
|
+
def row
|
14
14
|
@row = Row.new
|
15
|
-
|
15
|
+
yield
|
16
16
|
@table.add(@row)
|
17
17
|
end
|
18
18
|
|
data/zsh/gpr.zsh
CHANGED
@@ -23,6 +23,8 @@ function _gpr () {
|
|
23
23
|
'(-)*:: :->null_state' \
|
24
24
|
&& ret=0
|
25
25
|
;;
|
26
|
+
(select)
|
27
|
+
;;
|
26
28
|
(contrib)
|
27
29
|
;;
|
28
30
|
(search)
|
@@ -54,7 +56,8 @@ __gpr_cmds () {
|
|
54
56
|
'get:Get a repository'
|
55
57
|
'help:Describe available commands or one specific command'
|
56
58
|
'list:Show all registered repositories'
|
57
|
-
'
|
59
|
+
'select:Select a repository using the interactive interface'
|
60
|
+
'contrib:Show your contributions of registered repositories'
|
58
61
|
'search:Search the specified keyword in registered repositories'
|
59
62
|
'update:Update the database to be used for search'
|
60
63
|
'fetch:Fetch the registered repositories'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaihar4
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: curses
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -118,6 +132,9 @@ files:
|
|
118
132
|
- lib/graph_drawer.rb
|
119
133
|
- lib/graph_drawer/data.rb
|
120
134
|
- lib/graph_drawer/graph.rb
|
135
|
+
- lib/interactive_filter.rb
|
136
|
+
- lib/interactive_filter/input.rb
|
137
|
+
- lib/interactive_filter/interface.rb
|
121
138
|
- lib/table_builder.rb
|
122
139
|
- lib/table_builder/column.rb
|
123
140
|
- lib/table_builder/column_validator.rb
|