git-fancy 0.1.0 → 0.1.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/README.md +26 -12
- data/exe/sb +5 -0
- data/exe/switch-branch +49 -24
- data/lib/git/fancy/version.rb +1 -1
- 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: 685d5e178fb8233c3c22be3c24618b164c8e11ef96b809dada54ee831ffdd04e
|
4
|
+
data.tar.gz: ce0556c30dfb4e1b3ec8ff83b3f1fc19fb10c890696ec609358f2ce7c81bb4c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d00a35e7f8e172ba10759dae5a62c6eee46f5519f54e66295dbfa51a0958c55b40edc3d2fb9583b91562a4de51a646d1f87b3191ae7a5ac320f77b8fb7426cd4
|
7
|
+
data.tar.gz: cbcd6327de0c9b9708d4cd1e75f383515f2bd84c5aaab6263df43afb890330aead57333f5627a7f40d020389890010eaccf88eda59d41feb3c132e90cc9c9b97
|
data/README.md
CHANGED
@@ -1,28 +1,42 @@
|
|
1
1
|
# Git::Fancy
|
2
2
|
|
3
|
-
|
3
|
+
Git fancy is a command line tool that makes switching between git branches faster and easier.
|
4
|
+
It also allows you to annotate branches and quickly match branches based on either part of the branch name or notes.
|
4
5
|
|
5
|
-
|
6
|
+
Git fancy tracks branches by most recently used.
|
6
7
|
|
7
|
-
|
8
|
+

|
8
9
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
10
|
|
11
|
-
|
11
|
+
## Installation
|
12
12
|
|
13
|
-
```
|
14
|
-
|
13
|
+
```console
|
14
|
+
$ gem install git-fancy
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
## Usage
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
The `sb` command is an alias for `switch-branch`. Both commands can be used interchangeably.
|
20
|
+
|
21
|
+
To list recently used branches: (sb only tracks recently used branches when you use sb to switch branches)
|
22
|
+
```console
|
23
|
+
sb
|
21
24
|
```
|
22
25
|
|
23
|
-
|
26
|
+
To switch to a branch when you only have a portion of a branch name:
|
27
|
+
```console
|
28
|
+
sb <portion_of_branch_name>
|
29
|
+
```
|
30
|
+
|
31
|
+
To annotate the current branch you are on:
|
32
|
+
```console
|
33
|
+
sb -n "make the logo bigger"
|
34
|
+
```
|
24
35
|
|
25
|
-
|
36
|
+
List all of the branches git fancy is tracking:
|
37
|
+
```console
|
38
|
+
sb -l
|
39
|
+
```
|
26
40
|
|
27
41
|
## Development
|
28
42
|
|
data/exe/sb
ADDED
data/exe/switch-branch
CHANGED
@@ -4,10 +4,13 @@
|
|
4
4
|
# Switch to git branch by matching part of a name
|
5
5
|
|
6
6
|
require 'optparse'
|
7
|
+
require 'pastel'
|
7
8
|
require 'tty-prompt'
|
8
9
|
require 'tty-logger'
|
9
10
|
require 'sqlite3'
|
10
11
|
require 'git/fancy'
|
12
|
+
require 'open3'
|
13
|
+
require 'debug'
|
11
14
|
|
12
15
|
options = {}
|
13
16
|
|
@@ -27,12 +30,31 @@ OptionParser.new do |opts|
|
|
27
30
|
end
|
28
31
|
end.parse!
|
29
32
|
|
33
|
+
logger = TTY::Logger.new do |config|
|
34
|
+
config.handlers = [[:console, {
|
35
|
+
styles: {
|
36
|
+
info: {
|
37
|
+
color: :green,
|
38
|
+
symbol: '→',
|
39
|
+
label: nil,
|
40
|
+
levelpad: 0,
|
41
|
+
},
|
42
|
+
warn: {
|
43
|
+
label: nil,
|
44
|
+
},
|
45
|
+
error: {
|
46
|
+
label: nil,
|
47
|
+
},
|
48
|
+
}
|
49
|
+
}]]
|
50
|
+
end
|
51
|
+
@logger = logger
|
52
|
+
|
30
53
|
Signal.trap('TERM') do
|
31
|
-
|
54
|
+
@logger.error 'Terminating...'
|
32
55
|
shutdown
|
33
56
|
end
|
34
57
|
|
35
|
-
logger = TTY::Logger.new
|
36
58
|
|
37
59
|
@search_term = ARGV[0]&.strip
|
38
60
|
search_term = @search_term
|
@@ -48,7 +70,7 @@ end
|
|
48
70
|
|
49
71
|
if options[:delete_history]
|
50
72
|
@branch_history.purge_history!
|
51
|
-
logger.success @color.green('Removed branch history')
|
73
|
+
@logger.success @color.green('Removed branch history')
|
52
74
|
exit 0
|
53
75
|
end
|
54
76
|
|
@@ -62,22 +84,22 @@ end
|
|
62
84
|
if options[:note]
|
63
85
|
@branch_history.add_branch @branch_history.current_branch
|
64
86
|
@branch_history.add_note options[:note]
|
65
|
-
logger.success @color.green('Note added')
|
87
|
+
@logger.success @color.green('Note added')
|
66
88
|
exit 0
|
67
89
|
end
|
68
90
|
|
69
91
|
if options[:list]
|
70
92
|
branches = @branch_history.recent_branches(limit: 20, include_current: true)
|
71
93
|
if branches.empty?
|
72
|
-
logger.warn 'No recent branches found'
|
94
|
+
@logger.warn 'No recent branches found'
|
73
95
|
exit 0
|
74
96
|
end
|
75
97
|
|
76
|
-
|
98
|
+
@logger.info 'Recent branches:'
|
77
99
|
branches.each do |branch|
|
78
|
-
time = branch.last_accessed ? Time.at(branch.last_accessed).strftime('%
|
100
|
+
time = branch.last_accessed ? Time.at(branch.last_accessed).strftime('%Y-%m-%d') : nil
|
79
101
|
note = branch.note ? @color.yellow(branch.note) : nil
|
80
|
-
puts [time, branch.name, note].compact.join('
|
102
|
+
puts [time, branch.name, note].compact.join(@color.dim(' → '))
|
81
103
|
end
|
82
104
|
exit 0
|
83
105
|
end
|
@@ -99,32 +121,35 @@ end
|
|
99
121
|
branches = find_branches(search_term) || []
|
100
122
|
|
101
123
|
def switch_branch(branch_name, location:)
|
102
|
-
|
103
|
-
|
124
|
+
Open3.popen3("git switch #{branch_name}") do |stdin, stdout, stderr, wait_thr|
|
125
|
+
# For some reason, even succesful git switch goes to stderr
|
126
|
+
out = stderr.read
|
127
|
+
if wait_thr.value.success?
|
128
|
+
@logger.success @color.green(out.strip)
|
129
|
+
else
|
130
|
+
# Also for some reason errors are duplicated
|
131
|
+
@logger.error @color.red(out.split("\nerror: ").first.strip)
|
132
|
+
exit 1
|
133
|
+
end
|
134
|
+
end
|
104
135
|
|
105
136
|
@branch_history.add_branch(branch_name)
|
106
137
|
branch_note = @branch_history.branches_matching_notes(@search_term).find { |b| b.name == branch_name }&.note if @search_term
|
107
|
-
logger.success "Switched to #{location} branch: #{branch_name} #{branch_note ? @color.yellow(branch_note) : ''}"
|
108
138
|
end
|
109
139
|
|
110
140
|
def select_branch(branches, location: 'local', selected_branch: nil)
|
111
|
-
logger = TTY::Logger.new
|
112
|
-
prompt = TTY::Prompt.new
|
113
|
-
|
114
141
|
choices = branches.each_with_object({}) do |branch, hash|
|
115
142
|
time = branch.last_accessed ? Time.at(branch.last_accessed).strftime('%y-%m-%d') : nil
|
116
143
|
note = branch.note ? @color.yellow(branch.note) : nil
|
117
144
|
key = [time, branch.name, note].compact.join(' -- ')
|
118
145
|
hash[key] = branch.name
|
119
146
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
switch_branch(selection, location:)
|
147
|
+
prompt = TTY::Prompt.new
|
148
|
+
cancel_str = @color.dim('ctrl-c to cancel')
|
149
|
+
selection = prompt.select("Choose #{location} branch #{cancel_str}", choices)
|
150
|
+
switch_branch(selection, location:) if selection != 'none'
|
151
|
+
rescue TTY::Reader::InputInterrupt
|
152
|
+
exit 0
|
128
153
|
end
|
129
154
|
|
130
155
|
if branches.length == 1
|
@@ -135,10 +160,10 @@ if branches.length == 1
|
|
135
160
|
|
136
161
|
switch_branch(branch_name, location: 'local')
|
137
162
|
elsif branches.length > 1
|
138
|
-
logger.warn 'More than one branch name matched'
|
163
|
+
@logger.warn 'More than one branch name matched' if search_term
|
139
164
|
select_branch(branches, location: 'local')
|
140
165
|
else
|
141
|
-
logger.warn "No local branches named: '#{branches.join(', ')}' with that name were found"
|
166
|
+
@logger.warn "No local branches named: '#{branches.join(', ')}' with that name were found"
|
142
167
|
remote_branches = prep_branch_results(`git branch -r | grep #{search_term} | cut -f 1`)
|
143
168
|
|
144
169
|
select_branch(remote_branches, location: 'remote')
|
data/lib/git/fancy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-fancy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean McCleary
|
@@ -56,6 +56,7 @@ description: This gem is a tool to switch between recent branches and add notes
|
|
56
56
|
email:
|
57
57
|
- seanmcc@gmail.com
|
58
58
|
executables:
|
59
|
+
- sb
|
59
60
|
- switch-branch
|
60
61
|
extensions: []
|
61
62
|
extra_rdoc_files: []
|
@@ -67,6 +68,7 @@ files:
|
|
67
68
|
- LICENSE.txt
|
68
69
|
- README.md
|
69
70
|
- Rakefile
|
71
|
+
- exe/sb
|
70
72
|
- exe/switch-branch
|
71
73
|
- lib/git/fancy.rb
|
72
74
|
- lib/git/fancy/branch_history.rb
|