gitflash 0.1.2.alpha
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +48 -0
- data/bin/console +15 -0
- data/bin/gitflash +6 -0
- data/bin/setup +8 -0
- data/lib/gitflash/cli.rb +102 -0
- data/lib/gitflash/git/bash_command.rb +17 -0
- data/lib/gitflash/git/wrapper.rb +58 -0
- data/lib/gitflash/prompt.rb +46 -0
- data/lib/gitflash/version.rb +5 -0
- data/lib/gitflash.rb +17 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e2ab919eb4408a42c7bbd519e063a8f749e5c76802f078a410934bd6bf0faec
|
4
|
+
data.tar.gz: e821bb291632e98b292a0b6df49ede8836566904342026e9aa6693c8a0367ca6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5f855639bd9cee9d4761198e37e86a5b76e3ce6641a35be10602aaeb2698524aedf6c0fb4df761f3fcb3e306629ced9816586c8f5c0adea7e9acdcacca3636f5
|
7
|
+
data.tar.gz: 8a90c367cea30c5bbc242bb73eced1907e773a6e6cbad0d3673f4cf07a27bbcc1c972256d60eafde834cdc1134de2fcc3142ee2c4c8d7aad1faaa7e2c1dfa48d
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Kleanthismits
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# GitFlash
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/gitflash)
|
4
|
+
|
5
|
+
⚠️ **This project is stil under development**: Use at your own risk!
|
6
|
+
|
7
|
+
This gem allows you to use some of the most common git commands in a more user intuitive way.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'gitflash'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install gitflash
|
24
|
+
|
25
|
+
## Requirements
|
26
|
+
|
27
|
+
This gem requires Ruby 2.7+.
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Run `gitflash` to get a list with the available commands and their description.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git_flash. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/git_flash/blob/master/CODE_OF_CONDUCT.md).
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
45
|
+
|
46
|
+
## Code of Conduct
|
47
|
+
|
48
|
+
Everyone interacting in the GitFlash project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/git_flash/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'gitflash'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/gitflash
ADDED
data/bin/setup
ADDED
data/lib/gitflash/cli.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Gitflash
|
6
|
+
class Cli < Thor
|
7
|
+
def self.exit_on_failure?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'checkout', 'Checkout the selected branch'
|
12
|
+
long_desc <<-TEXT
|
13
|
+
|
14
|
+
Presents a list with all the available local branches.
|
15
|
+
|
16
|
+
You can use the arrow keys to navigate through the branches.
|
17
|
+
Type for quick searching a specific branch.
|
18
|
+
Press `enter` to choose and checkout the branch.
|
19
|
+
Press `ctrl+c` to cancel the operation.
|
20
|
+
TEXT
|
21
|
+
|
22
|
+
def checkout
|
23
|
+
branches? ? checkout_branch : prompt.ok('You only have one branch!')
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'delete', 'Delete the selected branches'
|
27
|
+
long_desc <<-TEXT
|
28
|
+
|
29
|
+
Presents a list with all the available local branches(without current or main/master).
|
30
|
+
|
31
|
+
You can use the arrow keys to navigate through the branches.
|
32
|
+
Type for quick searching a specific branch.
|
33
|
+
Press `space` to choose multiple branches.
|
34
|
+
Press `enter` to confirm selection and delete branches.
|
35
|
+
Press `ctrl+c` to cancel the operation.
|
36
|
+
|
37
|
+
WARNING: The branches will be deleted even if they have unmerged changes!!
|
38
|
+
TEXT
|
39
|
+
|
40
|
+
def delete
|
41
|
+
branches? ? delete_branch : prompt.ok('You only have one branch!')
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def checkout_branch
|
47
|
+
selection = prompt.select(
|
48
|
+
'Select a branch to checkout',
|
49
|
+
branches,
|
50
|
+
**checkout_options
|
51
|
+
)
|
52
|
+
|
53
|
+
git.checkout(selection)
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_branch
|
57
|
+
selection = prompt.multi_select(
|
58
|
+
'Select branches to delete',
|
59
|
+
branches(options: { master: false, current: false })
|
60
|
+
)
|
61
|
+
|
62
|
+
prompt.warn(<<~TEXT
|
63
|
+
You are about to permanently delete the following branches even if they have unmerged changes:
|
64
|
+
|
65
|
+
#{selection.map { |br| "* #{br}" }.join("\n")}
|
66
|
+
TEXT
|
67
|
+
)
|
68
|
+
answer = prompt.yes?('Do you want to proceed?')
|
69
|
+
puts answer ? git.delete(selection) : 'Exited'
|
70
|
+
end
|
71
|
+
|
72
|
+
def branches?
|
73
|
+
all_branches && all_branches.size > 1
|
74
|
+
end
|
75
|
+
|
76
|
+
def prompt
|
77
|
+
@prompt ||= Prompt.create
|
78
|
+
end
|
79
|
+
|
80
|
+
def checkout_options
|
81
|
+
{}.tap do |opt|
|
82
|
+
opt[:default] = current unless current.nil?
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def branches(options: {})
|
87
|
+
git.local_branches(**options)
|
88
|
+
end
|
89
|
+
|
90
|
+
def all_branches
|
91
|
+
@all_branches ||= git.all_local_branches
|
92
|
+
end
|
93
|
+
|
94
|
+
def current
|
95
|
+
@current ||= git.current_branch
|
96
|
+
end
|
97
|
+
|
98
|
+
def git
|
99
|
+
Gitflash::Git::Wrapper
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Gitflash
|
3
|
+
module Git
|
4
|
+
class Wrapper
|
5
|
+
HIDDEN_BRANCHES = %w[–show-current].freeze
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def local_branches(current: true, master: true)
|
9
|
+
formatted_branches.tap do |branches|
|
10
|
+
hidden_branches(current, master).each { |br| branches.delete(br) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_local_branches
|
15
|
+
formatted_branches
|
16
|
+
end
|
17
|
+
|
18
|
+
def current_branch
|
19
|
+
bash.exec('git branch --show-current').strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def checkout(branch)
|
23
|
+
bash.system_exec('git', 'checkout', branch)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(selection)
|
27
|
+
bash.system_exec('git', 'branch', '-D', *selection)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def hidden_branches(current, master)
|
33
|
+
[].tap { |hb|
|
34
|
+
hb.push('master') unless master
|
35
|
+
hb.push('main') unless master
|
36
|
+
hb.push(current_branch) unless current
|
37
|
+
} + HIDDEN_BRANCHES
|
38
|
+
end
|
39
|
+
|
40
|
+
def formatted_branches
|
41
|
+
raw_branches.map do |str|
|
42
|
+
next str unless str.start_with?('* ')
|
43
|
+
|
44
|
+
str.gsub('* ', '')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def raw_branches
|
49
|
+
bash.exec('git branch').strip.split("\n").map(&:strip)
|
50
|
+
end
|
51
|
+
|
52
|
+
def bash
|
53
|
+
BashCommand
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tty-prompt'
|
4
|
+
|
5
|
+
module Gitflash
|
6
|
+
# A wrapper class for TTY::Prompt gem
|
7
|
+
class Prompt < TTY::Prompt
|
8
|
+
class << self
|
9
|
+
def create(options: {})
|
10
|
+
new(options)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(options)
|
15
|
+
super(**default_create_options(options))
|
16
|
+
end
|
17
|
+
|
18
|
+
def select(message, collection, options = {})
|
19
|
+
super(message, collection, default_select_options(options))
|
20
|
+
end
|
21
|
+
|
22
|
+
def multi_select(message, collection, options = {})
|
23
|
+
super(message, collection, default_select_options(options))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_reader :prompt
|
29
|
+
|
30
|
+
def default_create_options(options)
|
31
|
+
{
|
32
|
+
interrupt: :exit,
|
33
|
+
quiet: true
|
34
|
+
}.merge(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_select_options(options)
|
38
|
+
{
|
39
|
+
cycle: true,
|
40
|
+
per_page: 50,
|
41
|
+
filter: true,
|
42
|
+
symbols: { marker: '>' }
|
43
|
+
}.merge(options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/gitflash.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Suppress the zeitwerk warning for overriding :require method temporarily
|
4
|
+
original_verbose = $VERBOSE
|
5
|
+
$VERBOSE = nil
|
6
|
+
|
7
|
+
require 'zeitwerk'
|
8
|
+
require 'pry'
|
9
|
+
|
10
|
+
loader = Zeitwerk::Loader.for_gem
|
11
|
+
loader.setup
|
12
|
+
|
13
|
+
# Restore the original warning level
|
14
|
+
$VERBOSE = original_verbose
|
15
|
+
|
16
|
+
module Gitflash
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitflash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2.alpha
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kleanthis Mitsioulis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem allows you to perform a number of git commands using interactive
|
14
|
+
cli prompts
|
15
|
+
email:
|
16
|
+
- kleanthismits@hotmail.gr
|
17
|
+
executables:
|
18
|
+
- gitflash
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files:
|
21
|
+
- README.md
|
22
|
+
files:
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- bin/console
|
26
|
+
- bin/gitflash
|
27
|
+
- bin/setup
|
28
|
+
- lib/gitflash.rb
|
29
|
+
- lib/gitflash/cli.rb
|
30
|
+
- lib/gitflash/git/bash_command.rb
|
31
|
+
- lib/gitflash/git/wrapper.rb
|
32
|
+
- lib/gitflash/prompt.rb
|
33
|
+
- lib/gitflash/version.rb
|
34
|
+
homepage: https://github.com/Kleanthismits/git_flash
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/Kleanthismits/git_flash
|
39
|
+
source_code_uri: https://github.com/Kleanthismits/git_flash
|
40
|
+
changelog_uri: https://github.com/Kleanthismits/git_flash/blob/main/CHANGELOG.md
|
41
|
+
rubygems_mfa_required: 'true'
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.7.0
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.3.1
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.2.15
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Simplified usage of some git cli commands
|
61
|
+
test_files: []
|