amusing_git 0.0.1

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: ebb244bba979ea95783388ddb3385b541ebcd8a7
4
+ data.tar.gz: b2a840156c1e6defae8df5d6f7014b1dcd3492f4
5
+ SHA512:
6
+ metadata.gz: e58a78ad0000b0f033fda86c4299321cf5343e52afc77780cd5ace99f879a7ce46c7a84ed01c984a7332901d9e42db681fe91c36977c60a84e5ba69cf164ab66
7
+ data.tar.gz: 7486e1e6e705c74cb1bf53500022176ac395636d1dad06be6cf3513f6b2f4ea84cbb5122b66e7828ca53d57968202ebf777b90947e0a75c79776026976bd5fdb
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gem 'thor', '~> 0.20.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,13 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ thor (0.20.0)
5
+
6
+ PLATFORMS
7
+ ruby
8
+
9
+ DEPENDENCIES
10
+ thor (~> 0.20.0)
11
+
12
+ BUNDLED WITH
13
+ 1.14.6
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative './lib/amusing_git/version.rb'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'amusing_git'
8
+ s.version = AmusingGit::VERSION
9
+ s.summary = 'Brings fun to the git workflow!'
10
+ s.description = s.summary
11
+ s.authors = ['Ajit Singh']
12
+ s.email = 'jeetsingh.ajit@gamil.com'
13
+ s.license = 'MIT'
14
+ s.homepage = 'https://github.com/ajitsing/amusing_git.git'
15
+
16
+ s.files = `git ls-files -z`.split("\x0")
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'thor', '~> 0.20.0'
22
+ s.add_development_dependency "bundler", "~> 1.5"
23
+ end
data/bin/amusing_git ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/amusing_git'
3
+
4
+ AmusingGit::CLI.start(ARGV)
@@ -0,0 +1,2 @@
1
+ project_root = File.dirname(File.absolute_path(__FILE__))
2
+ Dir.glob(project_root + '/amusing_git/**/*.rb', &method(:require))
@@ -0,0 +1,53 @@
1
+ require_relative './pretty_printer'
2
+ require_relative './git/git_repository'
3
+
4
+ module AmusingGit
5
+ class Amuser
6
+ include AmusingGit::PrettyPrinter
7
+
8
+ def amuse
9
+ begin
10
+ msgs = messages
11
+ print_info(msgs[rand(0..msgs.size-1)] + "\n")
12
+ rescue
13
+ print_error "Error reading amusing git config file\n"
14
+ return
15
+ end
16
+ end
17
+
18
+ def start_amusing(dir)
19
+ unless AmusingGit::GitRepository.git_repo? dir
20
+ print_error "#{dir} is not a git repository, halting...\n"
21
+ return
22
+ end
23
+
24
+ git_repository = AmusingGit::GitRepository.new dir
25
+ git_repository.create_hooks! unless git_repository.has_hooks?
26
+ git_repository.configure_amusing_git!
27
+
28
+ print_success "Done :)\n"
29
+ end
30
+
31
+ def stop_amusing(dir)
32
+ unless AmusingGit::GitRepository.git_repo? dir
33
+ print_error "#{dir} is not a git repository, halting...\n"
34
+ return
35
+ end
36
+
37
+ git_repository = AmusingGit::GitRepository.new dir
38
+ return unless git_repository.has_hooks?
39
+ git_repository.remove_amusing_git!
40
+
41
+ print_success "Done :)\n"
42
+ end
43
+
44
+ private
45
+ def messages
46
+ File.read(config["messages"]).split("\n")
47
+ end
48
+
49
+ def config
50
+ JSON.parse(File.read("#{ENV["HOME"]}/.amusing_git/config"))
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,45 @@
1
+ require 'thor'
2
+ require_relative './setup'
3
+ require_relative './amuser'
4
+
5
+ module AmusingGit
6
+ class CLI < Thor
7
+ include AmusingGit::PrettyPrinter
8
+
9
+ desc "start", "Start amusing for the current git repository"
10
+ def start
11
+ maybe_setup_amusing_git
12
+ amuser.start_amusing Dir.pwd
13
+ end
14
+
15
+ desc "stop", "Stop amusing for the current git repository"
16
+ def stop
17
+ maybe_setup_amusing_git
18
+ amuser.stop_amusing Dir.pwd
19
+ end
20
+
21
+ desc "amuse", "Print random messsage from configured messages"
22
+ def amuse
23
+ maybe_setup_amusing_git
24
+ amuser.amuse
25
+ end
26
+
27
+ desc "setup", "Setup amusing git"
28
+ def setup
29
+ amusing_git_setup.start
30
+ end
31
+
32
+ private
33
+ def maybe_setup_amusing_git
34
+ amusing_git_setup.start unless amusing_git_setup.setup_exists?
35
+ end
36
+
37
+ def amuser
38
+ @amuser ||= AmusingGit::Amuser.new
39
+ end
40
+
41
+ def amusing_git_setup
42
+ @amusing_git_setup ||= AmusingGit::Setup.new
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ module AmusingGit
2
+ class GitHook
3
+ def initialize(hook_file)
4
+ @hook_file = hook_file
5
+ end
6
+
7
+ def exists?
8
+ File.file? @hook_file
9
+ end
10
+
11
+ def create!
12
+ `touch #{@hook_file}`
13
+ `chmod +x #{@hook_file}`
14
+ end
15
+
16
+ def configure_amusing_git!
17
+ `echo "amusing_git amuse" >> #{@hook_file}`
18
+ end
19
+
20
+ def remove_amusing_git!
21
+ content = File.read(@hook_file)
22
+ new_content = content.gsub('amusing_git amuse', '')
23
+ File.open(@hook_file, 'w').write(new_content)
24
+ end
25
+
26
+ def amusing?
27
+ File.read(@hook_file).include? 'amusing_git amuse'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ require_relative './git_hook'
2
+
3
+ module AmusingGit
4
+ class GitRepository
5
+ def initialize(dir)
6
+ @dir = dir
7
+ end
8
+
9
+ def has_hooks?
10
+ File.exists? "#{@dir}/.git/hooks"
11
+ end
12
+
13
+ def create_hooks!
14
+ `mkdir -p .git/hooks`
15
+ end
16
+
17
+ def configure_amusing_git!
18
+ hooks.each do |hook|
19
+ hook.create! unless hook.exists?
20
+ hook.configure_amusing_git! unless hook.amusing?
21
+ end
22
+ end
23
+
24
+ def remove_amusing_git!
25
+ hooks.each do |hook|
26
+ hook.remove_amusing_git! if hook.amusing?
27
+ end
28
+ end
29
+
30
+ def self.git_repo? dir
31
+ File.exists? "#{dir}/.git"
32
+ end
33
+
34
+ private
35
+ def hooks
36
+ ["#{@dir}/.git/hooks/pre-push", "#{@dir}/.git/hooks/pre-rebase"].map { |h| AmusingGit::GitHook.new h}
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,44 @@
1
+ module AmusingGit
2
+ class MessageSeeder
3
+ def self.seed
4
+ <<-MESSAGES
5
+ Why does the computer programmer ignore the warning on the cigarette carton? Because he's seen so many warnings he only cares about errors.
6
+ What does the computer programmer say to his fellow programmer when he asks him to borrow $1000? I'll give you 1024 to make it even.
7
+ How does a network administrator nerd greet people who come to his house? Welcome to 127.0.0.1.
8
+ Beware of computer programmers that carry screwdrivers :P
9
+ If at first you don't succeed; call it version 1.0
10
+ If Python is executable pseudocode, then perl is executable line noise.
11
+ Programmers are tools for converting caffeine into code.
12
+ Hey! It compiles! Ship it!
13
+ SUPERCOMPUTER: what it sounded like before you bought it.
14
+ Windows Vista: It's like upgrading from Bill Clinton to George W. Bush.
15
+ My software never has bugs. It just develops random features.
16
+ The only problem with troubleshooting is that sometimes trouble shoots back.
17
+ Relax, its only ONES and ZEROS !
18
+ rm -rf /bin/laden
19
+ The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
20
+ If brute force doesn't solve your problems, then you aren't using enough.
21
+ Unix is user-friendly. It's just very selective about who its friends are.
22
+ I'm not anti-social; I'm just not user friendly
23
+ The world is coming to an end... SAVE YOUR BUFFERS !
24
+ If you don't want to be replaced by a computer, don't act like one.
25
+ There are 10 types of people in the world: those who understand binary, and those who don't.
26
+ Difference between a virus and windows ? Viruses rarely fail.
27
+ I think Microsoft named .Net so it wouldn’t show up in a Unix directory listing
28
+ If debugging is the process of removing bugs, then programming must be the process of putting them in.
29
+ Any fool can use a computer. Many do.
30
+ Hardware: The parts of a computer system that can be kicked.
31
+ They don't make bugs like Bunny anymore
32
+ When someone says: 'I want a programming language in which I need only say what I wish done', give him a lollipop.
33
+ Good design adds value faster than it adds cost.
34
+ Python's a drop-in replacement for BASIC in the sense that Optimus Prime is a drop-in replacement for a truck.
35
+ Talk is cheap. Show me the code.
36
+ Perl – The only language that looks the same before and after RSA encryption
37
+ Beware of bugs in the above code; I have only proved it correct, not tried it.
38
+ I don't care if it works on your machine! We are not shipping your machine!
39
+ Sometimes it pays to stay in bed on Monday, rather than spending the rest of the week debugging Monday's code.
40
+ Measuring programming progress by lines of code is like measuring aircraft building progress by weight.
41
+ MESSAGES
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ module AmusingGit
2
+ module PrettyPrinter
3
+ def colorize(text, color_code)
4
+ "#{color_code}#{text}\e[0m"
5
+ end
6
+
7
+ def red(text); colorize(text, "\e[31m"); end
8
+ def green(text); colorize(text, "\e[32m"); end
9
+ def yellow(text); colorize(text, "\e[1m\e[33m"); end
10
+
11
+ def print_info(msg)
12
+ STDOUT.write yellow(msg)
13
+ end
14
+
15
+ def print_error(msg)
16
+ STDOUT.write red(msg)
17
+ end
18
+
19
+ def print_success(msg)
20
+ STDOUT.write green(msg)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+ require_relative './pretty_printer'
3
+ require_relative './message_seeder'
4
+
5
+ module AmusingGit
6
+ class Setup
7
+ include AmusingGit::PrettyPrinter
8
+
9
+ def start
10
+ if setup_exists?
11
+ print_info "You already have amusing git setup, skipping...\n"
12
+ return
13
+ end
14
+
15
+ print_info "Setting up amusing git configuration...\n"
16
+ create_amusing_git_dir
17
+ write_config
18
+ copy_messages
19
+ print_success "Setup is completed!\n"
20
+ end
21
+
22
+ def setup_exists?
23
+ File.exists? "#{ENV['HOME']}/.amusing_git"
24
+ end
25
+
26
+ private
27
+ def create_amusing_git_dir
28
+ `mkdir #{ENV['HOME']}/.amusing_git`
29
+ end
30
+
31
+ def write_config
32
+ File.open(config_file, "w") do |f|
33
+ f.write(JSON.pretty_generate(config))
34
+ end
35
+ end
36
+
37
+ def copy_messages
38
+ File.open("#{ENV['HOME']}/.amusing_git/default_messages", 'w').write(AmusingGit::MessageSeeder.seed)
39
+ end
40
+
41
+ def config_file
42
+ File.new("#{ENV['HOME']}/.amusing_git/config", "w")
43
+ end
44
+
45
+ def config
46
+ {
47
+ "messages" => "#{ENV['HOME']}/.amusing_git/default_messages"
48
+ }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module AmusingGit
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amusing_git
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ajit Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.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.20.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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ description: Brings fun to the git workflow!
42
+ email: jeetsingh.ajit@gamil.com
43
+ executables:
44
+ - amusing_git
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - amusing_git.gemspec
51
+ - bin/amusing_git
52
+ - lib/amusing_git.rb
53
+ - lib/amusing_git/amuser.rb
54
+ - lib/amusing_git/cli.rb
55
+ - lib/amusing_git/git/git_hook.rb
56
+ - lib/amusing_git/git/git_repository.rb
57
+ - lib/amusing_git/message_seeder.rb
58
+ - lib/amusing_git/pretty_printer.rb
59
+ - lib/amusing_git/setup.rb
60
+ - lib/amusing_git/version.rb
61
+ homepage: https://github.com/ajitsing/amusing_git.git
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.13
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Brings fun to the git workflow!
85
+ test_files: []