alfred_git 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 127a29a45aeb9d4c99b537dd79b6b54fa042c51c
4
+ data.tar.gz: 0d201b61f4e64c304331a8bb7318164bb9ab1b33
5
+ SHA512:
6
+ metadata.gz: c873b2eeb4c41ef0acc08a33a862e6c64150dee0cc0a4f93799cc2e6e4cbb40ab580792c1d736b8a9b1a15376f2e842a5ddeead3dac380d6a4ac268f518f478e
7
+ data.tar.gz: 302ae66c3c6157cb4fc4692d9a6cf38c74358f2ee92a70fbfef4fd725f8a092580b055657d14b5c7674f39e117c5c7bdd96a9bcc8bc80006265f49301a0bcbf2
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ lib/config.yaml
2
+ .idea
3
+ .bundle
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rainbow', '~>2.1.0'
4
+ gem 'gemspec'
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 iamsellek
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,102 @@
1
+ # AlfredGit
2
+ Helps you handle multiple git repos more quickly and easily.
3
+
4
+ ## Longer Description
5
+ Guys. We live in 2016. When Marty visited the future, he now visited *last
6
+ year.* Cars are now out there driving. *Themselves*. We are *half a
7
+ century* removed from sending a man to another celestial body and without even
8
+ blowing him up in the process. Why on Earth (heh), then, do I need to cd into
9
+ every single repo I'm working with on a project and type individual git commands
10
+ in every one of them?
11
+
12
+ You know, some guy back in the 20s had a similar question. Why did he have to
13
+ do all this stupid 'math' crap by hand? And do you know what he did? He punched
14
+ math in the face and invented freaking computers (I don't know my computer
15
+ history very well). I...well, to be honest, I'm doing something a tad less
16
+ monumental, but I am that man. A modern what's-his-name-you-know-the-guy-who-
17
+ hated-math-and-invented-computers-if-that-story-is-even-real(-it's-not).
18
+
19
+ Enter AlfredGit, named after a certain famous billionaire's butler. AlfredGit does
20
+ those stupid menial typing tasks for you. Why? Because you're freaking Batman
21
+ and Batman doesn't have time to sit there cd-ing into 12 different repo
22
+ directories and issuing a `git pull` in every single one of them. He's too
23
+ busy out there punching...uh...bugs and...feature requests. In the face (this
24
+ analogy is quickly falling apart). So grab AlfredGit and say goodbye to
25
+ spending 20% of your day typing git commands in 140 different repos like a
26
+ pleb. This, guys. This is the future.
27
+
28
+ # Installation
29
+
30
+ I'd recommend holding off on this for right now, as I'm planning on gem-ifying
31
+ this soon enough. Once that's done, an install will be as easy as typing `gem
32
+ install alfred` or something similar. Pretty sure someone already took that
33
+ gem name even though their app doesn't even compare and doesn't deserve the
34
+ moniker.
35
+
36
+ # Use
37
+
38
+ I've tried to make the command syntax as intuitive as possible. Essentially,
39
+ you'll send in a few parameters (the exact number of parameters required
40
+ changes based on what git command you need to run - you can't run a `git
41
+ checkout` without a branch name, for instance) separated by spaces; the repos
42
+ you want to work with *always* come last and will also be separated by spaces.
43
+ Want to do all of the repos, but don't want to type them all out? Of course
44
+ you do! Why else would you be using this app? Just run AlfredGit with the word
45
+ 'all' as your last parameter.
46
+
47
+ AlfredGit comes packaged with the most common git commands built in, but also
48
+ allows you to send custom commands! If your first parameter doesn't match
49
+ any of the built-in commands, the first parameter itself will be the command
50
+ that is run! Simple! Think another command warrants being on this list?
51
+ Email me and I'll consider adding it!
52
+
53
+ And with that, we come to the built-in commands. Here are the AlfredGit commands
54
+ followed by a description of what they run. Most of these should be intuitive.
55
+
56
+ * `pull` - Runs a `git pull`
57
+ * `push` - Runs a `git push`
58
+ * `checkout second_parameter` - runs a `git checkout second_parameter`
59
+ * `commit second_parameter` - Runs a `git commit -m second_parameter`
60
+ * `status` - Runs a `git status`
61
+ * `branch` or `branches` - Lists the branches your repos currently have
62
+ checked out.
63
+
64
+ # Quick Example
65
+ Here's a quick example of how it works!
66
+
67
+ Want to pull repos 1, 2, and 3? Easy!
68
+
69
+ `> alfred_git pull repo_1 repo_2 repo_3`
70
+
71
+ What about pulling everything?
72
+
73
+ `> alfred_git pull all`
74
+
75
+ How about checking out a branch on multiple repos at once?
76
+
77
+ `> alfred_git checkout branch_name repo_1 repo_2`
78
+
79
+ See? Intuitive! Simple! Batman!
80
+
81
+ ## License
82
+ The MIT License (MIT)
83
+
84
+ Copyright (c) 2016 Chris Sellek
85
+
86
+ Permission is hereby granted, free of charge, to any person obtaining a copy
87
+ of this software and associated documentation files (the "Software"), to deal
88
+ in the Software without restriction, including without limitation the rights
89
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
90
+ copies of the Software, and to permit persons to whom the Software is
91
+ furnished to do so, subject to the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be included in all
94
+ copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
97
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
98
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
99
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
100
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
101
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
102
+ SOFTWARE.
data/Rakefile.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/alfred.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alfred_git/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'alfred_git'
8
+ spec.version = AlfredGit::VERSION
9
+ spec.authors = ['Chris Sellek']
10
+ spec.email = ['iamsellek@gmail.com']
11
+
12
+ spec.summary = 'Helps you handle multiple git repos more quickly and easily.'
13
+ spec.description = 'See GitHub page for longer description.'
14
+ spec.homepage = 'https://github.com/iamsellek/alfred_git'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = ['alfred_git']
19
+ spec.test_files = []
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'rainbow'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.12'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ end
data/bin/alfred_git ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'alfred_git'
4
+
5
+ helper = AlfredGit::AlfredGit.new
6
+
7
+ helper.config if ARGV[0] == 'config'
8
+
9
+ helper.alfred(ARGV)
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alfred_git"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module AlfredGit
2
+ VERSION = "0.1.0"
3
+ end
data/lib/alfred_git.rb ADDED
@@ -0,0 +1,208 @@
1
+ require 'YAML'
2
+ require 'rainbow'
3
+
4
+ module AlfredGit
5
+ class AlfredGit
6
+
7
+ def initialize
8
+ set_app_directory
9
+ config unless File.exists?("#{@app_directory}/lib/config.yaml")
10
+ config_yaml = YAML.load_file("#{@app_directory}/lib/config.yaml")
11
+
12
+ @repo_locations = config_yaml['repos']
13
+ @name = config_yaml['name'].nil? ? 'Wayne' : config_yaml['name']
14
+ @gender = config_yaml['gender'].nil? ? 'sir' : config_yaml['gender']
15
+ end
16
+
17
+ def alfred(arguments)
18
+ @arguments = arguments
19
+ command = command_to_git_command
20
+ repos = repos_string_to_array
21
+
22
+ repos.each do |repo|
23
+ lines_pretty_print Rainbow("Repo #{repo}:").yellow
24
+ bash(@repo_locations[repo], command)
25
+
26
+ single_space
27
+ end
28
+ end
29
+
30
+ def command_to_git_command
31
+ command = ''
32
+
33
+ case @arguments[0]
34
+ when nil, ''
35
+ lines_pretty_print Rainbow('I need a command to run, Master Wayne.').red
36
+
37
+ abort
38
+ when 'pull'
39
+ command = 'git pull'
40
+ @arguments.delete_at(0)
41
+ when 'push'
42
+ command = 'git push'
43
+ @arguments.delete_at(0)
44
+ when 'checkout'
45
+ if second_argument_missing?
46
+ lines_pretty_print Rainbow('I need a branch name to execute the \'checkout\' command, Master '\
47
+ 'Wayne.').red
48
+
49
+ abort
50
+ end
51
+
52
+ command = "git checkout #{@arguments[1]}"
53
+
54
+ @arguments.delete_at(0)
55
+ @arguments.delete_at(0)
56
+ when 'commit'
57
+ if second_argument_missing?
58
+ lines_pretty_print Rainbow('I need a commit message to execute the \'commit\' command, Master '\
59
+ 'Wayne.').red
60
+
61
+ abort
62
+ end
63
+
64
+ command = %Q[git commit -m "#{@arguments[1]}"]
65
+ when 'status'
66
+ command = 'git status'
67
+ @arguments.delete_at(0)
68
+ when 'branches', 'branch'
69
+ command = 'git rev-parse --abbrev-ref HEAD'
70
+ @arguments.delete_at(0)
71
+ else
72
+ command = @arguments[0] # Allow users to send any command to all repos.
73
+ @arguments.delete_at(0)
74
+ end
75
+
76
+ command
77
+ end
78
+
79
+ # All other arguments are deleted before we get here, so this should be just the repo list.
80
+ def repos_string_to_array
81
+ if @arguments[0].nil?|| @arguments[0] == ''
82
+ lines_pretty_print Rainbow('I need at least one repository to work with, Master Wayne.').red
83
+
84
+ abort
85
+ elsif @arguments[0] == 'all'
86
+ return @repo_locations.keys
87
+ else
88
+ return @arguments
89
+ end
90
+ end
91
+
92
+ def config
93
+ config_file = File.open("#{@app_directory}/lib/config.yaml", 'w')
94
+
95
+ lines_pretty_print 'Good evening, Master Wayne. Thank you for utilizing my abilities. Please enter your '\
96
+ 'last name if you\'d like me to address you as something other than Wayne.'
97
+ lines_pretty_print Rainbow('(Just hit enter to stick with \'Master Wayne\'.)').yellow
98
+
99
+ name = STDIN.gets.strip!
100
+
101
+ single_space
102
+
103
+ lines_pretty_print 'Thank you, sir. You...are a sir, correct?'
104
+
105
+ gender_set = false
106
+
107
+ until gender_set
108
+ gender = STDIN.gets.strip!
109
+
110
+ single_space
111
+
112
+ if gender == 'yes' || gender == 'y'
113
+ gender = 'sir'
114
+ gender_set = true
115
+ elsif gender == 'no' || gender == 'n'
116
+ gender = 'madam'
117
+ gender_set = true
118
+ else
119
+ lines_pretty_print "Very funny, Master #{name}."
120
+ lines_pretty_print Rainbow('Please input either \'yes\' or \'no\'.').yellow
121
+ end
122
+ end
123
+
124
+ lines_pretty_print "Yes, of course. My apologies. Please do not take offense, #{gender}. I am, after "\
125
+ 'all, a simple computer program. Don\'t have eyes, you see. Now, let\'s gather a '\
126
+ 'list of the code repositories you work with, shall we?'
127
+
128
+ single_space
129
+
130
+ repos = {}
131
+ done = false
132
+ repo_count = 0
133
+
134
+ until done do
135
+ first = repo_count > 0 ? 'next' : 'first'
136
+
137
+ lines_pretty_print "What is the 'friendly' name you'd like to give your #{first} repository? This is the "\
138
+ 'name you will type when sending me commands. If you are done adding them, please '\
139
+ 'enter \'x211\' as your input instead.'
140
+
141
+ repo_name = STDIN.gets.strip!
142
+
143
+ if repo_name == 'x211'
144
+ done = true
145
+ single_space
146
+ next
147
+ end
148
+
149
+ single_space
150
+
151
+ lines_pretty_print "Thank you, #{gender}. Now, where is that repository? Please paste the full path."
152
+
153
+ repo_path = STDIN.gets.strip!
154
+
155
+ single_space
156
+
157
+ repos[repo_name] = repo_path
158
+ repo_count += 1
159
+
160
+ lines_pretty_print Rainbow("I've added that repository successfully, #{gender}!").green
161
+
162
+ single_space
163
+ end
164
+
165
+ YAML.dump({ 'name' => name, 'gender' => gender, 'repos' => repos }, config_file)
166
+ config_file.close
167
+
168
+ lines_pretty_print "Thank you for helping me set things up, Master #{name}. Feel free to run me whenever "\
169
+ 'you need.'
170
+
171
+ abort
172
+ end
173
+
174
+ def second_argument_missing?
175
+ @arguments[1].nil? || @arguments[1] == ''
176
+ end
177
+
178
+ def bash(directory, command)
179
+ # Dir.chdir ensures all bash commands are being run from the correct
180
+ # directory.
181
+ Dir.chdir(directory) { system "#{command}" }
182
+ end
183
+
184
+ def set_app_directory
185
+ @app_directory = File.expand_path(File.dirname(__FILE__)).chomp('/lib')
186
+ end
187
+
188
+ def lines_pretty_print(string)
189
+ lines = string.scan(/\S.{0,70}\S(?=\s|$)|\S+/)
190
+
191
+ lines.each { |line| puts line }
192
+ end
193
+
194
+ def single_space
195
+ puts ''
196
+ end
197
+
198
+ def double_space
199
+ puts "\n\n"
200
+ end
201
+
202
+ def surround_by_double_space(string)
203
+ double_space
204
+ lines_pretty_print(string)
205
+ double_space
206
+ end
207
+ end
208
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alfred_git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Sellek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: See GitHub page for longer description.
56
+ email:
57
+ - iamsellek@gmail.com
58
+ executables:
59
+ - alfred_git
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile.rb
68
+ - alfred.gemspec
69
+ - bin/alfred_git
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/alfred_git.rb
73
+ - lib/alfred_git/version.rb
74
+ homepage: https://github.com/iamsellek/alfred_git
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.14.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Helps you handle multiple git repos more quickly and easily.
98
+ test_files: []