command-genie 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: 11a2636ffc746bc889411db5f462c842f9424225
4
+ data.tar.gz: ddf02d4e967230bb8ffe61c60b11c1ad9057104f
5
+ SHA512:
6
+ metadata.gz: b92219021daa5967a8e22b1c417ebfddfadca0fb0601573b0399036b469f666077bd6f1a985dc43a38b5f497fe7a7d9a93438ac5902bf6f9aeb851212a4393d1
7
+ data.tar.gz: e814d32b16f7d0c1ebf80ba177bb2595a39e9574a72608dba80537fa3249de4e0b1d7808f1bdb08f2546b417e99132b2d3230b2970424fe30edbbadb6dd47615
data/.gitignore ADDED
@@ -0,0 +1,45 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+ vendor/Pods/
18
+ *.bridgesupport
19
+ build-iPhoneOS/
20
+ build-iPhoneSimulator/
21
+
22
+ ## Documentation cache and generated files:
23
+ /.yardoc/
24
+ /_yardoc/
25
+ /doc/
26
+ /rdoc/
27
+
28
+ ## Environment normalization:
29
+ /.bundle/
30
+ /vendor/bundle
31
+ /lib/bundler/man/
32
+
33
+ ## Mac
34
+ .DS_Store
35
+
36
+ # for a library or gem, you might want to ignore these files since the code is
37
+ # intended to run in multiple environments; otherwise, check them in:
38
+ # Gemfile.lock
39
+ # .ruby-version
40
+ # .ruby-gemset
41
+
42
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
43
+ .rvmrc
44
+
45
+ tags
data/LICENSE ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2016, Hwee-Boon Yar
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ About
2
+ ---
3
+ As developers, we try to automate and build shortcuts to improve our workflow. Sometimes we always run the same command in a specific project directory and a slightly different command or the same command with slightly different parameters in another.
4
+
5
+ A good example is when pushing code, we might run `git push origin master` for one repository, but for another, we might want to run `hub push origin,deploy master` instead. `genie` helps you do that.
6
+
7
+ `genie` lets you create commands that are bound to directories. In our example, we can create a `push` command that, depending on which directory we run it in, invoke the correct push command.
8
+
9
+ Usage
10
+ ---
11
+ Here's how to create a command with `genie`:
12
+
13
+ 1. Create a YAML configuration file matching the softlink in your user directory's `.config` directory. e.g. For the command called `push`, you would create `~/.config/push.yml`.
14
+
15
+ Contents for the YAML file are key-value mappings from a directory path to the command to be ran in that directory (and it's subdirectories):
16
+
17
+ ```
18
+ /Users/hboon/code/piggyalarm: git push bb master
19
+ /Users/hboon/code/simplymeta: hub push bb,deploy master
20
+ ~/code/ligify: git push bb master
21
+ ```
22
+
23
+ You can also run `genie create <command>` to help you create a sample YAML file.
24
+
25
+ 2. Create a softlink to `genie` with a sensible name and make sure it's in your $PATH, e.g.
26
+
27
+ ```
28
+ ln -s genie push
29
+ ```
30
+
31
+ Installation
32
+ ---
33
+ `gem install command-genie`
34
+
35
+ Dependencies
36
+ ---
37
+ * [commander](https://github.com/tj/commander)
38
+
39
+ License
40
+ ---
41
+ BSD
42
+
43
+ Questions
44
+ ---
45
+ * Email: [hboon@motionobj.com](mailto:hboon@motionobj.com)
46
+ * Web: [http://hboon.com/genie/](http://hboon.com/genie/)
47
+ * Twitter: [https://twitter.com/hboon](https://twitter.com/hboon)
data/bin/genie ADDED
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+ require 'fileutils'
6
+ require 'psych'
7
+
8
+ APP_NAME = 'genie'
9
+ HELP_STRING = "Create commands bound to directories. E.g. create a `push` command
10
+ that, depending on which directory you are in, run the correct git
11
+ push command.
12
+
13
+ ----------
14
+
15
+ You can either create the command and config file
16
+ semi-automatically:
17
+
18
+ 1. Run:
19
+
20
+ $ #{APP_NAME} create <command>
21
+
22
+ This will create a YAML file `~/.config/#{APP_NAME}/<command>.yml`
23
+ and the command (a softlink) in the current directory.
24
+
25
+ 2. Move this softlink to a directory in your $PATH so that you can
26
+ run the command anywhere.
27
+
28
+ $ mv <command> /some/directory/included/in/path/
29
+
30
+ ----------
31
+
32
+ Alternatively, you can create them manually:
33
+
34
+ 1. Figure out where `#{APP_NAME}` is installed.
35
+
36
+ $ which #{APP_NAME}
37
+
38
+ 2. Create a softlink to `#{APP_NAME}` with a sensible name and make
39
+ sure this softlink is in your $PATH. This will be your new command
40
+ e.g.
41
+
42
+ $ ln -s /full/path/to/#{APP_NAME}/from/step1 push
43
+
44
+ 3. Create a YAML configuration file matching the softlink in your
45
+ user directory's `.config/#{APP_NAME}/` directory. e.g. For the
46
+ command called `push`, you would create
47
+ `~/.config/#{APP_NAME}/push.yml`.
48
+
49
+ Contents for the YAML file are key-value mappings from a directory
50
+ path to the command to be ran in that directory (and its
51
+ subdirectories):
52
+
53
+ ---
54
+ /Users/hboon/code/piggyalarm: git push bb master
55
+ /Users/hboon/code/simplymeta: hub push bb,deploy master
56
+ ~/code/ligify: git push bb master
57
+
58
+ ---
59
+
60
+ Either way, update the configuration file at
61
+ `~/.config/#{APP_NAME}/<command>.yml` with the commands for each
62
+ directory.
63
+ "
64
+ TICK_CHAR = "\u2713"
65
+
66
+ program :version, '0.0.1'
67
+ program :description, HELP_STRING
68
+
69
+ script_name = File.basename(__FILE__)
70
+
71
+ if script_name == APP_NAME
72
+ default_command :create
73
+ else
74
+ default_command :run
75
+ end
76
+
77
+ def config_path(cmd)
78
+ File.expand_path("~/.config/#{APP_NAME}/#{cmd}.yml")
79
+ end
80
+
81
+ if script_name != APP_NAME
82
+ cmd_config_path = config_path(script_name)
83
+ command :run do |c|
84
+ c.syntax = "#{script_name}"
85
+ c.summary = "Run a command from #{cmd_config_path} that matches the current directory"
86
+ c.description = "Run a command from #{cmd_config_path} that matches the current directory"
87
+ c.example 'Run command', "$ #{script_name}"
88
+ c.action do |args, options|
89
+ #Careful, say doesn't return true-ish
90
+ if (script_name == APP_NAME && (args.nil? || args.empty?))
91
+ say HELP_STRING
92
+ abort
93
+ end
94
+ say_error "Specify the name of the new command you want to create:
95
+
96
+ #{APP_NAME} create <command>
97
+ " and abort if script_name == APP_NAME
98
+ File.open(cmd_config_path) do |f|
99
+ mapping = Psych.load(f.read)
100
+ mapping = Hash[mapping.map{|k,v|[k.chomp('/'), v]}]
101
+ dir = Dir.pwd
102
+ found = dir_matching(mapping.keys, dir)
103
+ cmd = mapping[found]
104
+ if cmd && !cmd.empty?
105
+ say "Running: #{cmd}"
106
+ `#{cmd}`
107
+ else
108
+ say_error "No matching command found for `#{dir}`."
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ if script_name == APP_NAME
116
+ command :create do |c|
117
+ c.syntax = "#{script_name}"
118
+ c.summary = "Create a command"
119
+ c.description = "Create a command"
120
+ c.example 'Create command', "$ #{APP_NAME} create <command>"
121
+ c.action do |args, options|
122
+ say_error "Specify the name of the new command you want to create:
123
+
124
+ #{APP_NAME} create <command>
125
+ " and abort if args.nil? || args.empty?
126
+ new_cmd = args[0]
127
+ say_error "I don't think you want to do that." and abort if new_cmd == APP_NAME
128
+ cmd_config_path = config_path(new_cmd)
129
+ config_dir = File.dirname(cmd_config_path)
130
+ say_error "A file with the same name as the command/softlink `#{new_cmd}` already exist." and abort if File.file? new_cmd
131
+ say_error "Configuration file `#{cmd_config_path}` already exist." and abort if File.file? cmd_config_path
132
+ create_configuration_file(new_cmd, config_dir)
133
+ create_command(new_cmd)
134
+ end
135
+ end
136
+ end
137
+
138
+ def dir_matching(dirs, dir)
139
+ found = dirs.find {|e|e == dir || File.expand_path(e) == dir}
140
+ if found
141
+ found
142
+ else
143
+ dir = File.expand_path('..', dir)
144
+ if dir == '/'
145
+ nil
146
+ else
147
+ dir_matching(dirs, dir)
148
+ end
149
+ end
150
+ end
151
+
152
+ def genie_abs_path
153
+ @genie_abs_path ||= `which genie`.chomp
154
+ end
155
+
156
+ def create_configuration_file(new_cmd, config_dir)
157
+ dir = Dir.pwd
158
+ contents = "#{dir}: ENTER_YOUR_COMMAND_HERE
159
+ /another_directory_path: ENTER_ANOTHER_COMMAND
160
+ /yet_another_directory_path: AND_ANOTHER_COMMAND
161
+ ~/some_dir: AND_ANOTHER_COMMAND"
162
+ cmd_config_path = config_path(new_cmd)
163
+ FileUtils.mkdir_p(config_dir) unless File.directory? config_dir
164
+ File.open(cmd_config_path, 'w') {|f| f.write(contents)}
165
+ say "#{TICK_CHAR} Configuration file `#{cmd_config_path}` created."
166
+ end
167
+
168
+ def create_command(new_cmd)
169
+ `ln -s #{genie_abs_path} #{new_cmd}`
170
+ say "#{TICK_CHAR} New command (softlink) `#{new_cmd}` created by genie."
171
+ say "TODO: You should move `#{new_cmd}` to a directory included in your $PATH so you can use it anywhere."
172
+ end
data/genie.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/genie/version.rb', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'command-genie'
6
+ gem.authors = ['Hwee-Boon Yar']
7
+ gem.email = 'hboon@motionobj.com'
8
+ gem.version = CommandGenie::VERSION
9
+
10
+ gem.licenses = ['BSD']
11
+ gem.summary = 'genie — Run commands that are bound to directories.'
12
+ gem.description = gem.summary
13
+ gem.homepage = 'http://hboon.com/genie/'
14
+
15
+ gem.add_dependency 'commander', '~> 4.3'
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = ['genie']
18
+ gem.require_paths = ['lib']
19
+ #gem.test_files = gem.files.grep(%r{^spec/})
20
+ end
data/lib/genie.rb ADDED
@@ -0,0 +1 @@
1
+ require 'genie/genie'
File without changes
@@ -0,0 +1,3 @@
1
+ module CommandGenie
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: command-genie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hwee-Boon Yar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: commander
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.3'
27
+ description: genie — Run commands that are bound to directories.
28
+ email: hboon@motionobj.com
29
+ executables:
30
+ - genie
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - LICENSE
36
+ - README.md
37
+ - bin/genie
38
+ - genie.gemspec
39
+ - lib/genie.rb
40
+ - lib/genie/genie.rb
41
+ - lib/genie/version.rb
42
+ homepage: http://hboon.com/genie/
43
+ licenses:
44
+ - BSD
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.4.8
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: genie — Run commands that are bound to directories.
66
+ test_files: []