gnav 0.4.0 → 0.5.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/README.md +4 -2
- data/assets/gnav_theme.jpeg +0 -0
- data/bin/release/gnav +2 -1
- data/gnav.gemspec +1 -1
- data/lib/git_prompt.rb +8 -7
- data/lib/gnav/version.rb +1 -1
- data/lib/treeish/base.rb +40 -0
- data/lib/treeish/branch.rb +31 -0
- data/lib/treeish/tag.rb +40 -0
- data/lib/treeish.rb +4 -0
- metadata +10 -5
- data/lib/treeish_extractor.rb +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 461cd758fbbc755e021b202984abf8b9c8d7c1583cbf0f9bdd713525b96d4cf8
|
4
|
+
data.tar.gz: 72bfd88113b7e3812297111a276179483a40ee6691e004628edaa9e54f6be261
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a85384ae7857c2a9a3462f7c4e4b657d4232c7f328c9a12351a0cb781946861c114ad260101f1226e05ba7ba0fd949f1f61272ac6e3fab3915c30935fa7ec912
|
7
|
+
data.tar.gz: 669492c957964ac382d43d0dc74dcc3938f5c2fd0f0358ddbb50f67643e3148ccd26f86de54fab6fa73477607c7ee14f40c8cd2c024fc5f97c5826142371b8fa
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# GNav
|
2
2
|
|
3
|
-
`gnav` is
|
3
|
+
`gnav` is an simple command line tool for interactively checking out a git tag or branch.
|
4
|
+
|
5
|
+
<img src='assets/gnav_theme.jpeg' width="260" alt='Gnav theme' />
|
4
6
|
|
5
7
|
|
6
8
|
## Installation
|
@@ -8,7 +10,7 @@
|
|
8
10
|
Simply, install it with gem.
|
9
11
|
|
10
12
|
```shell
|
11
|
-
$ gem
|
13
|
+
$ gem install gnav
|
12
14
|
```
|
13
15
|
|
14
16
|
|
Binary file
|
data/bin/release/gnav
CHANGED
@@ -4,7 +4,8 @@ require 'cli'
|
|
4
4
|
require "rubygems"
|
5
5
|
require_relative '../../lib/gnav.rb'
|
6
6
|
|
7
|
-
|
7
|
+
file = File.expand_path('../../../', __FILE__)
|
8
|
+
gemspec = Gem::Specification::load("#{file}/gnav.gemspec")
|
8
9
|
|
9
10
|
CLI.new do
|
10
11
|
description gemspec.description
|
data/gnav.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["ttsysuzuki@googlemail.com"]
|
8
8
|
|
9
9
|
spec.summary = 'Interactive git tag and branch selector'
|
10
|
-
spec.description = '`gnav` is
|
10
|
+
spec.description = '`gnav` is an simple command line tool for interactively checking out a git tag or branch.'
|
11
11
|
spec.homepage = 'https://github.com/suzukimilanpaak/gnav'
|
12
12
|
|
13
13
|
spec.license = "MIT"
|
data/lib/git_prompt.rb
CHANGED
@@ -3,21 +3,22 @@
|
|
3
3
|
require 'git'
|
4
4
|
require 'tty-prompt'
|
5
5
|
require 'logger'
|
6
|
-
require_relative './
|
7
|
-
require_relative './monkey_patches/tty/prompt
|
6
|
+
require_relative './treeish'
|
7
|
+
require_relative './monkey_patches/tty/prompt'
|
8
8
|
|
9
9
|
class GitPrompt
|
10
10
|
SELECT_OPTIONS_PER_PAGE = 10
|
11
11
|
|
12
|
-
attr_reader :git, :
|
12
|
+
attr_reader :git, :branch, :tag, :prompt, :logger
|
13
13
|
|
14
14
|
def initialize(git: nil)
|
15
15
|
@git = git || Git.open(Dir.pwd)
|
16
|
-
@
|
16
|
+
@branch = Treeish::Branch.new(git: git)
|
17
|
+
@tag = Treeish::Tag.new(git: git)
|
17
18
|
|
18
19
|
create_prompt
|
19
20
|
define_key_events
|
20
|
-
display_select(:branch,
|
21
|
+
display_select(:branch, branch.recents)
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
@@ -42,12 +43,12 @@ class GitPrompt
|
|
42
43
|
|
43
44
|
if event.value == 'b'
|
44
45
|
prompt.clear!
|
45
|
-
display_select(:branch,
|
46
|
+
display_select(:branch, branch.recents)
|
46
47
|
end
|
47
48
|
|
48
49
|
if event.value == 't'
|
49
50
|
prompt.clear!
|
50
|
-
display_select(:tag,
|
51
|
+
display_select(:tag, tag.recents)
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
data/lib/gnav/version.rb
CHANGED
data/lib/treeish/base.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'git'
|
4
|
+
require 'open3'
|
5
|
+
|
6
|
+
module Treeish
|
7
|
+
class Base
|
8
|
+
attr_reader :git
|
9
|
+
|
10
|
+
def initialize(git: nil)
|
11
|
+
@git = git || Git.open(Dir.pwd)
|
12
|
+
end
|
13
|
+
|
14
|
+
def recents
|
15
|
+
get_treeishes(recents_command) do |line, names|
|
16
|
+
next if reject_strategy(line, names)
|
17
|
+
names << {
|
18
|
+
value: value_strategy(line, names),
|
19
|
+
name: name_strategy(line, names)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def recents_command; end
|
27
|
+
def reject_strategy(line, names); end
|
28
|
+
def value_strategy(line, names); end
|
29
|
+
def name_strategy(line, names); end
|
30
|
+
|
31
|
+
def get_treeishes(cmd)
|
32
|
+
names = []
|
33
|
+
_stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
|
34
|
+
stdout.each(sep="\n") do |line|
|
35
|
+
yield(line, names)
|
36
|
+
end
|
37
|
+
names
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './base'
|
4
|
+
|
5
|
+
module Treeish
|
6
|
+
class Branch < Base
|
7
|
+
private
|
8
|
+
|
9
|
+
def recents_command
|
10
|
+
'git branch --sort=-committerdate'
|
11
|
+
end
|
12
|
+
|
13
|
+
def reject_strategy(line, _)
|
14
|
+
# 'HEAD detached' means the last commit is detached from its HEAD.
|
15
|
+
# We don't need this information and remove it.
|
16
|
+
line =~ /HEAD detached/
|
17
|
+
end
|
18
|
+
|
19
|
+
def value_strategy(line, _)
|
20
|
+
line.sub('*', '').strip
|
21
|
+
end
|
22
|
+
|
23
|
+
def name_strategy(line, _)
|
24
|
+
if line.match(/\*\s/)
|
25
|
+
line.strip
|
26
|
+
else
|
27
|
+
" #{line.strip}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/treeish/tag.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './base'
|
4
|
+
|
5
|
+
module Treeish
|
6
|
+
class Tag < Base
|
7
|
+
private
|
8
|
+
|
9
|
+
def recents_command
|
10
|
+
'git tag --sort=-committerdate'
|
11
|
+
end
|
12
|
+
|
13
|
+
def reject_strategy(line, _)
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def value_strategy(line, _)
|
18
|
+
line.strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def name_strategy(line, _)
|
22
|
+
if line.match(/^#{current}$/)
|
23
|
+
"* #{line.strip}"
|
24
|
+
else
|
25
|
+
" #{line.strip}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def current
|
30
|
+
# git describe --exact-match --tags $(git log -n1 --pretty='%h')
|
31
|
+
cmd = "git log -n1 --pretty='%h'"
|
32
|
+
_stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
|
33
|
+
last_commit = stdout.read.strip
|
34
|
+
|
35
|
+
cmd = "git describe --exact-match --tags #{last_commit}"
|
36
|
+
_stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
|
37
|
+
stdout.read.strip || '[\s]+'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/treeish.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnav
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuya Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin/release
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -72,7 +72,8 @@ dependencies:
|
|
72
72
|
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
|
-
description: "`gnav` is
|
75
|
+
description: "`gnav` is an simple command line tool for interactively checking out
|
76
|
+
a git tag or branch."
|
76
77
|
email:
|
77
78
|
- ttsysuzuki@googlemail.com
|
78
79
|
executables:
|
@@ -90,6 +91,7 @@ files:
|
|
90
91
|
- LICENSE.txt
|
91
92
|
- README.md
|
92
93
|
- Rakefile
|
94
|
+
- assets/gnav_theme.jpeg
|
93
95
|
- bin/console
|
94
96
|
- bin/release/gnav
|
95
97
|
- bin/setup
|
@@ -98,7 +100,10 @@ files:
|
|
98
100
|
- lib/gnav.rb
|
99
101
|
- lib/gnav/version.rb
|
100
102
|
- lib/monkey_patches/tty/prompt.rb
|
101
|
-
- lib/
|
103
|
+
- lib/treeish.rb
|
104
|
+
- lib/treeish/base.rb
|
105
|
+
- lib/treeish/branch.rb
|
106
|
+
- lib/treeish/tag.rb
|
102
107
|
homepage: https://github.com/suzukimilanpaak/gnav
|
103
108
|
licenses:
|
104
109
|
- MIT
|
@@ -121,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
126
|
- !ruby/object:Gem::Version
|
122
127
|
version: '0'
|
123
128
|
requirements: []
|
124
|
-
rubygems_version: 3.
|
129
|
+
rubygems_version: 3.1.6
|
125
130
|
signing_key:
|
126
131
|
specification_version: 4
|
127
132
|
summary: Interactive git tag and branch selector
|
data/lib/treeish_extractor.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'git'
|
4
|
-
require 'open3'
|
5
|
-
|
6
|
-
class TreeishExtractor
|
7
|
-
attr_reader :git
|
8
|
-
|
9
|
-
def initialize(git: nil)
|
10
|
-
@git = git || Git.open(Dir.pwd)
|
11
|
-
end
|
12
|
-
|
13
|
-
def recent_tag_names
|
14
|
-
cmd = 'git tag --sort=-committerdate'
|
15
|
-
get_treeishes(cmd) do |line, names|
|
16
|
-
names << {
|
17
|
-
value: line.strip,
|
18
|
-
name: line.strip
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def recent_branch_names
|
24
|
-
cmd = 'git branch --sort=-committerdate'
|
25
|
-
get_treeishes(cmd) do |line, names|
|
26
|
-
next if REJECT_STRATEGY.call(line, names).nil?
|
27
|
-
names << {
|
28
|
-
value: VALUE_STRATEGY.call(line, names),
|
29
|
-
name: NAME_STRATEGY.call(line, names)
|
30
|
-
}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
REJECT_STRATEGY = lambda do |line, _|
|
37
|
-
# 'HEAD detached' means the last commit is detached from its HEAD.
|
38
|
-
# We don't need this information and remove it.
|
39
|
-
line unless line =~ /HEAD detached/
|
40
|
-
end
|
41
|
-
VALUE_STRATEGY = lambda do |line, _|
|
42
|
-
line.sub('*', '').strip
|
43
|
-
end
|
44
|
-
NAME_STRATEGY = lambda do |line, _|
|
45
|
-
if line.match(/\*\s/)
|
46
|
-
line.strip
|
47
|
-
else
|
48
|
-
" #{line.sub('*', '').strip}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_treeishes(cmd)
|
53
|
-
names = []
|
54
|
-
_stdin, stdout, _stderr, _wait_thr = Open3.popen3(cmd)
|
55
|
-
stdout.each(sep="\n") do |line|
|
56
|
-
yield(line, names)
|
57
|
-
end
|
58
|
-
names
|
59
|
-
end
|
60
|
-
end
|