G4t 1.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/g4t +2 -0
  3. data/lib/g4t.rb +252 -0
  4. metadata +74 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5987fcbc6ee6dccf87c591bf40001b17f2c75a69baea76a92ad083fe3bbb01ef
4
+ data.tar.gz: 6aaea7514763c842f14cb4efa4504d717eae30b071c2c72ca417c43ad979c9d4
5
+ SHA512:
6
+ metadata.gz: e1781ddfda3d078abcf66d6249a6de7b99851d0ad3322921fe5730543f18a54b43dee16537361bb2be66b744dac3e7af003f653f8df1887586f4a60f3a74e7d6
7
+ data.tar.gz: a0a5875defce772ea407bc9fb1d9d176e233b108413de510afd516ef4cce070fcbeb2d581f49437bd28b6397e059750bd57970bb54e0a8a595c8ab49fb42f1c2
data/bin/g4t ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require "g4t"
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ require "os"
4
+ require "tty-prompt"
5
+ require "etc"
6
+
7
+ module G4t
8
+ class Options
9
+ def initialize
10
+ $prompt = TTY::Prompt.new
11
+ end
12
+
13
+ def commit_files
14
+ $lastmsg = "Now that we commited the files"
15
+ msg = $prompt.ask("Commit message:")
16
+
17
+ if msg[0] != "\""
18
+ msg = "\"#{msg}"
19
+ end
20
+
21
+ if msg[-1] != "\""
22
+ msg = "#{msg}\""
23
+ end
24
+
25
+ puts msg
26
+ run_command("git commit -m #{msg}")
27
+ end
28
+
29
+ def add_files
30
+ $lastmsg = "Now that we added the files"
31
+ all_files = $prompt.yes?("Add all files?")
32
+ if all_files
33
+ cmd = "git add ."
34
+ puts("Adding all files...")
35
+ else
36
+ fname = $prompt.ask("File to add:")
37
+ cmd = "git add #{fname}"
38
+ end
39
+ run_command("#{cmd}")
40
+ end
41
+
42
+ def logs
43
+ run_command("git log")
44
+ end
45
+
46
+ def push_branch
47
+ branch = $prompt.ask("Branch to push:")
48
+ run_command("git push origin #{branch}")
49
+ end
50
+
51
+ def remote_adress
52
+ $lastmsg = "Now that we the remote address"
53
+ uname = $prompt.ask("Your github username:")
54
+ repo = $prompt.ask("Your repository name:")
55
+ puts("Adding remote repository https://github.com/#{uname}/#{repo}...")
56
+ run_command("git remote add origin https://github.com/#{uname}/#{repo}.git")
57
+ end
58
+
59
+ def status
60
+ run_command("git status")
61
+ end
62
+
63
+ def clone_repo
64
+ uname = $prompt.ask("Username:")
65
+ repo = $prompt.ask("Repository name:")
66
+ run_command("git clone https://github.com/#{uname}/#{repo}/")
67
+ end
68
+
69
+ def restore
70
+ fname = $prompt.ask("File name:")
71
+ run_command("git restore #{fname}")
72
+ end
73
+
74
+ def reset
75
+ commit = $prompt.ask("Commit id:")
76
+ run_command("git reset --hard #{commit}")
77
+ end
78
+
79
+ def hard_reset
80
+ confirmation = $prompt.yes?("do you really want to hard reset?")
81
+
82
+ if confirmation
83
+ run_command("git reset --hard HEAD~")
84
+ else
85
+ puts "Cancelling operation"
86
+ end
87
+
88
+ end
89
+
90
+ def initialize_git
91
+ $lastmsg = "Now that we initialized .git"
92
+ puts("Initializing Git repository in '#{Dir.pwd}/.git'...")
93
+ run_command("git init")
94
+ end
95
+
96
+ def diff
97
+ run_command("git diff")
98
+ end
99
+
100
+ def change_branch
101
+ bname = $prompt.ask("Branch name:")
102
+ run_command("git checkout -b #{bname}")
103
+ end
104
+
105
+ def git_info
106
+ status = {
107
+ "Git branch" => IO.popen("git branch"),
108
+ "Repository url" => IO.popen("git config --get remote.origin.url")
109
+ }
110
+ status.each do |k, v|
111
+ puts("#{k}: #{v.read}")
112
+ end
113
+ puts("____________\n\n")
114
+ end
115
+
116
+ def remove_file
117
+ file_name = $prompt.ask("Enter the file name: ")
118
+ run_command("git rm #{file_name}")
119
+ end
120
+
121
+ def show_last_commit
122
+ run_command("git show")
123
+ end
124
+
125
+ def pull_changes
126
+ git_pull_options = ["rebase", "no-rebase", "ff-only"]
127
+ chose = $prompt.select("chose: ", git_pull_options)
128
+ run_command("git pull --#{chose}")
129
+ end
130
+
131
+ def run_command(cmd)
132
+ puts "Command: #{cmd}"
133
+ system(cmd)
134
+ end
135
+ end
136
+
137
+ class Run
138
+ def initialize
139
+ @opt = Options.new
140
+ git_init?
141
+ start
142
+ end
143
+
144
+ def verify_system
145
+ if OS.windows?; "C:\\Users\\#{Etc.getlogin}\\.gitconfig" else "/home/#{Etc.getlogin}/.gitconfig" end
146
+ end
147
+
148
+ def git_init?
149
+ identify_user
150
+ unless File.directory?(".git")
151
+ begin
152
+ options = ["Clone a repo", "Initialize a repo", "Close"]
153
+ @git_init_select = $prompt.select("The .git directory was not found, what do you want to do?", options)
154
+ git_init_verify
155
+ rescue TTY::Reader::InputInterrupt
156
+ abort("\nCloseed")
157
+ end
158
+ end
159
+ end
160
+
161
+ def git_init_verify
162
+ case @giti_init_select
163
+ when "Clone a repo"
164
+ @opt.clone_repo
165
+ when "Init a repo"
166
+ @opt.init_repo
167
+ else
168
+ abort("It is not possible to continue without a .git repository or cloned repository!")
169
+ end
170
+ end
171
+
172
+ def identify_user
173
+ if(File.exist?(verify_system)) == false
174
+ begin
175
+ email = $prompt.ask("Github email: ")
176
+ uname = $prompt.ask("Github username: ")
177
+ self.run("git config --global user.email #{email} && git config --global user.name #{uname}")
178
+ rescue TTY::Reader::InputInterrupt
179
+ abort("\nYou closed the application")
180
+ end
181
+ end
182
+ end
183
+
184
+ def show_panel
185
+ options = ["Add remote address",
186
+ "Add files",
187
+ "Commit files",
188
+ "Push files to branch",
189
+ "Show git status",
190
+ "Show git logs",
191
+ "Show the last commit",
192
+ "Remove a file",
193
+ "Show diff",
194
+ "Change branch",
195
+ "Git pull changes",
196
+ "Restore a file",
197
+ "Reset to a commit",
198
+ "Reset to the last commit",
199
+ "Close"
200
+ ]
201
+
202
+ begin
203
+ @opt.git_info
204
+ @opt_select = $prompt.select("Select: ", options)
205
+ verify_option
206
+ rescue TTY::Reader::InputInterrupt
207
+ abort("\nYou has closed the application.")
208
+ end
209
+ end
210
+
211
+ def verify_option
212
+ case @opt_select
213
+ when "Add remote address" then
214
+ @opt.remote_adress
215
+ when "Add files" then
216
+ @opt.add_files
217
+ when "Commit files" then
218
+ @opt.commit_files
219
+ when "Push files to branch" then
220
+ @opt.push_branch
221
+ when "Show git status" then
222
+ @opt.status
223
+ when "Show git logs" then
224
+ @opt.logs
225
+ when "Show diff" then
226
+ @opt.diff
227
+ when "Restore a file" then
228
+ @opt.restore
229
+ when "Reset to a commit" then
230
+ @opt.reset
231
+ when "Reset to the last commit" then
232
+ @opt.hard_reset
233
+ when "Change branch" then
234
+ @opt.change_branch
235
+ when "Remove a file" then
236
+ @opt.remove_file
237
+ when "Show the last commit" then
238
+ @opt.show_last_commit
239
+ when "Git pull changes" then
240
+ @opt.pull_changes
241
+ else
242
+ abort("Goodbye, closed.")
243
+ end
244
+ end
245
+
246
+ def start
247
+ loop { show_panel }
248
+ end
249
+ end
250
+
251
+ Run.new
252
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: G4t
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - freazesss
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: os
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.22.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.22.0
41
+ description: A simple cli app to make the git commands more easy to you, commit, push
42
+ and etc.
43
+ email: freazesss@gmail.com
44
+ executables:
45
+ - g4t
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/g4t
50
+ - lib/g4t.rb
51
+ homepage: https://github.com/freazesss/g4t
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.1.2
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: git
74
+ test_files: []