git_selector 0.2.0 → 0.2.2
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/Gemfile.lock +1 -1
- data/lib/git_prompt.rb +14 -7
- data/lib/git_selector/version.rb +1 -1
- data/lib/monkey_patches/tty/prompt/list.rb +12 -0
- data/lib/monkey_patches/tty/prompt.rb +42 -0
- data/lib/treeish_extractor.rb +12 -6
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb239a7bd25eb04147c34c2abf08b85a0011c340de26c5ec6ab432f199fdcc68
|
4
|
+
data.tar.gz: b1d5fb88077a842a73e49906f23595920fca485272d3da4ca5d101d01da17e29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad33d9bf74f706bd203588628ad0fc4a91936545c8e50755791331481cb7e2e413c64b667a5bd21de7852b733005783a1b6203a0d7d02725da3681a99b566634
|
7
|
+
data.tar.gz: c4ff0b4254aaf8bc701790b64ec3bd2ada32e1b31a825db122b7dc5da4043bebf62473c837b77056d24312e8df2e59d3d84a98c10c4a8b083d33e383fe6332b1
|
data/Gemfile.lock
CHANGED
data/lib/git_prompt.rb
CHANGED
@@ -4,6 +4,7 @@ require 'git'
|
|
4
4
|
require 'tty-prompt'
|
5
5
|
require 'logger'
|
6
6
|
require_relative './treeish_extractor'
|
7
|
+
require_relative './monkey_patches/tty/prompt.rb'
|
7
8
|
|
8
9
|
class GitPrompt
|
9
10
|
SELECT_OPTIONS_PER_PAGE = 10
|
@@ -13,10 +14,10 @@ class GitPrompt
|
|
13
14
|
def initialize(git: nil)
|
14
15
|
@git = git || Git.open(Dir.pwd)
|
15
16
|
@extractor = TreeishExtractor.new(git: git)
|
16
|
-
@prompt = TTY::Prompt.new(quiet: true)
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
create_prompt
|
19
|
+
define_key_events
|
20
|
+
select_tag(extractor.recent_tag_names)
|
20
21
|
end
|
21
22
|
|
22
23
|
def define_key_events
|
@@ -25,6 +26,8 @@ class GitPrompt
|
|
25
26
|
exit
|
26
27
|
end
|
27
28
|
|
29
|
+
# move up/down in the list
|
30
|
+
|
28
31
|
if event.value == 'j'
|
29
32
|
prompt.trigger(:keydown)
|
30
33
|
end
|
@@ -33,6 +36,7 @@ class GitPrompt
|
|
33
36
|
prompt.trigger(:keyup)
|
34
37
|
end
|
35
38
|
|
39
|
+
# Select a mode
|
36
40
|
|
37
41
|
if event.value == 'b'
|
38
42
|
clear_prompt
|
@@ -49,8 +53,11 @@ class GitPrompt
|
|
49
53
|
private
|
50
54
|
|
51
55
|
def clear_prompt
|
52
|
-
|
53
|
-
|
56
|
+
prompt.clear_list
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_prompt
|
60
|
+
@prompt = TTY::Prompt.new(quiet: true)
|
54
61
|
end
|
55
62
|
|
56
63
|
def select_tag(treeish_names)
|
@@ -69,13 +76,13 @@ class GitPrompt
|
|
69
76
|
prompt.ok 'No tags were found'
|
70
77
|
end
|
71
78
|
rescue TTY::Reader::InputInterrupt => e
|
72
|
-
exit
|
79
|
+
# exit automatically
|
73
80
|
end
|
74
81
|
|
75
82
|
def checkout(tag_name)
|
76
83
|
git.checkout(tag_name)
|
84
|
+
exit
|
77
85
|
rescue Git::GitExecuteError => e
|
78
86
|
prompt.error(e.message)
|
79
87
|
end
|
80
88
|
end
|
81
|
-
|
data/lib/git_selector/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../git_prompt.rb'
|
4
|
+
require_relative './prompt/list.rb'
|
5
|
+
|
6
|
+
module TTY
|
7
|
+
class Prompt
|
8
|
+
|
9
|
+
# original - https://github.com/piotrmurach/tty-prompt/blob/master/lib/tty/prompt.rb#L226-L250
|
10
|
+
def invoke_select(object, question, *args, &block)
|
11
|
+
options = Utils.extract_options!(args)
|
12
|
+
choices = if args.empty? && !block
|
13
|
+
possible = options.dup
|
14
|
+
options = {}
|
15
|
+
possible
|
16
|
+
elsif args.size == 1 && args[0].is_a?(Hash)
|
17
|
+
Utils.extract_options!(args)
|
18
|
+
else
|
19
|
+
args.flatten
|
20
|
+
end
|
21
|
+
|
22
|
+
@list = object.new(self, **options)
|
23
|
+
@list.(question, choices, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def unsubscribe_list
|
27
|
+
self.unsubscribe(@list)
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear_list
|
31
|
+
@done = true
|
32
|
+
# @list = nil
|
33
|
+
unsubscribe_list
|
34
|
+
# 2 is for the prompt message
|
35
|
+
print(TTY::Cursor.clear_lines(GitPrompt::SELECT_OPTIONS_PER_PAGE + 2, :up))
|
36
|
+
end
|
37
|
+
|
38
|
+
def purge_list
|
39
|
+
@list = nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/treeish_extractor.rb
CHANGED
@@ -13,24 +13,30 @@ class TreeishExtractor
|
|
13
13
|
def recent_tag_names
|
14
14
|
# TODO unlimit number of tags when arg is given
|
15
15
|
cmd = "git describe --tags $(git rev-list --tags --max-count=1000)"
|
16
|
-
|
16
|
+
# reject commits without a tag
|
17
|
+
selecting_rule = ->(line, names) do
|
18
|
+
names << line.strip unless line =~ /-[\d]+-[a-z0-9]{8,}$/
|
19
|
+
end
|
20
|
+
get_treeish_names(cmd, selecting_rule)
|
17
21
|
end
|
18
22
|
|
19
23
|
def recent_branch_names
|
20
24
|
# TODO limit number of branches when arg is not given
|
21
25
|
cmd = 'git branch --sort=-committerdate'
|
22
|
-
|
26
|
+
# a current branch is prefixed with '* ' to indicate it's selected
|
27
|
+
selecting_rule = ->(line, names) do
|
28
|
+
names << line.strip.sub('* ', '') unless line =~ /HEAD detached/
|
29
|
+
end
|
30
|
+
get_treeish_names(cmd, selecting_rule)
|
23
31
|
end
|
24
32
|
|
25
33
|
private
|
26
34
|
|
27
|
-
def get_treeish_names(cmd)
|
35
|
+
def get_treeish_names(cmd, selecting_rule)
|
28
36
|
names = []
|
29
37
|
_stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
|
30
38
|
stdout.each(sep="\n") do |line|
|
31
|
-
|
32
|
-
# current branch has '* ' to indicate it's selected
|
33
|
-
names << line.strip.sub('* ', '') unless line =~ /-[\d]+-[a-z0-9]{8,}$/
|
39
|
+
selecting_rule.call(line, names)
|
34
40
|
end
|
35
41
|
names
|
36
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_selector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuya Suzuki
|
@@ -76,6 +76,8 @@ files:
|
|
76
76
|
- lib/git_prompt.rb
|
77
77
|
- lib/git_selector.rb
|
78
78
|
- lib/git_selector/version.rb
|
79
|
+
- lib/monkey_patches/tty/prompt.rb
|
80
|
+
- lib/monkey_patches/tty/prompt/list.rb
|
79
81
|
- lib/treeish_extractor.rb
|
80
82
|
homepage: https://github.com/suzukimilanpaak/git_selector
|
81
83
|
licenses:
|