commandify 0.0.3

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in commandify.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 richardcalahan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # Commandify
2
+
3
+ A bunch of really awesome, helpful and easy command line tools for Rails apps.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'commandify'
10
+
11
+ And then run:
12
+
13
+ $ bundle install
14
+ $ commandify install
15
+ $ source ~/.bashrc
16
+
17
+ Commandify adds aliases to `~/.bashrc` which evaluate strings returned by the Commandify gem in the context of your current shell. After install, `~/.bashrc` might look something like this:
18
+
19
+ # COMMANDIFY [VERSION NUMBER] #
20
+ alias r='eval $(bundle exec commandify r)'
21
+ alias m='eval $(bundle exec commandify m)'
22
+ alias v='eval $(bundle exec commandify v)'
23
+ ...
24
+ # COMMANDIFY END #
25
+
26
+ When updating Commandify to a newer version, simply re-run `commandify install`. It will load all new aliases automatically. If you've manually modified aliases in `~/.bashrc` and want to return to Commandify defaults, run `commandify install!` to force a re-installation.
27
+
28
+ ## Usage
29
+
30
+ ### Nagivation Commands
31
+
32
+ $ r # cd to root of rails app
33
+ $ m # cd to app/models
34
+ $ v # cd to app/views
35
+ $ c # cd to app/controllers
36
+ $ a # cd to app/assets
37
+ $ h # cd to app/helpers
38
+ $ j # cd to app/assets/javascripts
39
+ $ s # cd to app/assets/stylesheets
40
+ $ i # cd to app/assets/images
41
+ $ f # cd to app/assets/fonts
42
+ $ e # cd to config/environments
43
+ $ conf # cd to config
44
+ $ init # cd to config/initializers
45
+ $ db # cd to db
46
+ $ l # cd to lib
47
+ $ la # cd to lib/assets
48
+ $ lt # cd to lib/tasks
49
+ $ las # cd to lib/assets/stylesheets
50
+ $ laj # cd to lib/assets/javascripts
51
+ $ v # cd to vendor
52
+ $ va # cd to vendor/assets
53
+ $ vt # cd to vendor/tasks
54
+ $ vas # cd to vendor/assets/stylesheets
55
+ $ vaj # cd to vendor/assets/javascripts
56
+
57
+ ### Process Commands
58
+
59
+ $ srvstart # starts rails server on port 3000, automatically kills existing process on same port
60
+ $ srvstop # kills ruby process on port 3000
61
+ $ srvrestart # effectively the same thing as srvstart, might get rid of this one?
62
+
63
+ ## Contributing
64
+
65
+ 1. Fork it
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/commandify ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ case ARGV[0]
4
+ when 'install'
5
+ require 'commandify/install'
6
+ Commandify::Install.run
7
+ when 'install!'
8
+ require 'commandify/install'
9
+ Commandify::Install.run!
10
+ else
11
+ require 'commandify/command'
12
+ Commandify::Command.run ARGV[0]
13
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/commandify/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["richardcalahan"]
6
+ gem.email = ["richard@calahan.me"]
7
+ gem.description = 'Commandify your rails app!'
8
+ gem.summary = 'Amazingly helpful'
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "commandify"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Commandify::VERSION
17
+ end
@@ -0,0 +1,133 @@
1
+ require 'commandify/core'
2
+ require 'commandify/directories'
3
+
4
+ module Commandify
5
+
6
+ module Command
7
+
8
+ ALL = %w( r m v c a h j s i f conf e init db l la lt las laj v va vas vaj
9
+ srvstop srvstart srvrestart )
10
+
11
+ class << self
12
+
13
+ include Commandify::Core
14
+
15
+ def run command
16
+ send command
17
+ end
18
+
19
+ # Navigation
20
+
21
+ def r
22
+ goto Commandify::Directories::ROOT
23
+ end
24
+
25
+ def m
26
+ goto Commandify::Directories::MODELS
27
+ end
28
+
29
+ def v
30
+ goto Commandify::Directories::VIEWS
31
+ end
32
+
33
+ def c
34
+ goto Commandify::Directories::CONTROLLERS
35
+ end
36
+
37
+ def a
38
+ goto Commandify::Directories::ASSETS
39
+ end
40
+
41
+ def h
42
+ goto Commandify::Directories::HELPERS
43
+ end
44
+
45
+ def j
46
+ goto Commandify::Directories::JAVASCRIPTS
47
+ end
48
+
49
+ def s
50
+ goto Commandify::Directories::STYLESHEETS
51
+ end
52
+
53
+ def i
54
+ goto Commandify::Directories::IMAGES
55
+ end
56
+
57
+ def f
58
+ goto Commandify::Directories::FONTS
59
+ end
60
+
61
+ def conf
62
+ goto Commandify::Directories::CONFIG
63
+ end
64
+
65
+ def e
66
+ goto Commandify::Directories::CONFIG
67
+ end
68
+
69
+ def init
70
+ goto Commandify::Directories::INITIALIZERS
71
+ end
72
+
73
+ def db
74
+ goto Commandify::Directories::DB
75
+ end
76
+
77
+ def l
78
+ goto Commandify::Directories::LIB
79
+ end
80
+
81
+ def la
82
+ goto Commandify::Directories::LIB_ASSETS
83
+ end
84
+
85
+ def lt
86
+ goto Commandify::Directories::LIB_TASKS
87
+ end
88
+
89
+ def las
90
+ goto Commandify::Directories::LIB_ASSETS_STYLESHEETS
91
+ end
92
+
93
+ def laj
94
+ goto Commandify::Directories::LIB_ASSETS_JAVASCRIPTS
95
+ end
96
+
97
+ def v
98
+ goto Commandify::Directories::VENDOR
99
+ end
100
+
101
+ def va
102
+ goto Commandify::Directories::VENDOR_ASSETS
103
+ end
104
+
105
+ def vas
106
+ goto Commandify::Directories::VENDOR_ASSES_STYLESHEETS
107
+ end
108
+
109
+ def vaj
110
+ goto Commandify::Directories::VENDOR_ASSETS_JAVASCRIPTS
111
+ end
112
+
113
+ # Processes
114
+
115
+ def srvstop port=3000
116
+ system "sudo kill -9 #{server_pid(port)}"
117
+ end
118
+
119
+ def srvstart port=3000
120
+ srvstop port
121
+ system "rails server"
122
+ end
123
+
124
+ def srvrestart port=3000
125
+ srvstop port
126
+ srvstart port
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+ end
@@ -0,0 +1,29 @@
1
+ module Commandify
2
+
3
+ module Core
4
+
5
+ # returns shell commands to navigate directories in a rails app
6
+ def goto path
7
+ begin
8
+ raise unless File.exists? 'script/rails'
9
+ command << "cd #{path}; " if path
10
+ rescue
11
+ command << 'cd ..; '
12
+ Dir.chdir '..'
13
+ retry unless Dir.pwd == '/'
14
+ end
15
+ STDOUT.puts command.join
16
+ end
17
+
18
+ # get the pid of the current ruby process
19
+ def server_pid port
20
+ `lsof -i:#{port} | awk '/^ruby/ { print $2 }' `.to_i
21
+ end
22
+
23
+ def command
24
+ @@command ||= []
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,53 @@
1
+ module Commandify
2
+
3
+ module Directories
4
+
5
+ ROOT = nil
6
+
7
+ MODELS = 'app/models'
8
+
9
+ VIEWS = 'app/views'
10
+
11
+ CONTROLLERS = 'app/controllers'
12
+
13
+ ASSETS = 'app/assets'
14
+
15
+ HELPERS = 'app/helpers'
16
+
17
+ JAVASCRIPTS = 'app/assets/javascripts'
18
+
19
+ STYLESHEETS = 'app/assets/stylesheets'
20
+
21
+ IMAGES = 'app/assets/images'
22
+
23
+ FONTS = 'app/assets/fonts'
24
+
25
+ CONFIG = 'config'
26
+
27
+ ENVIRONMENTS = 'config/environments'
28
+
29
+ INITIALIZERS = 'config/initializers'
30
+
31
+ DB = 'db'
32
+
33
+ LIB = 'lib'
34
+
35
+ LIB_ASSETS = 'lib/assets'
36
+
37
+ LIB_ASSETS_STYLESHEETS = 'lib/assets/stylesheets'
38
+
39
+ LIB_ASSETS_JAVASCRIPTS = 'lib/assets/javascripts'
40
+
41
+ LIB_TASKS = 'lib/tasks'
42
+
43
+ VENDOR = 'vendor'
44
+
45
+ VENDOR_ASSETS = 'vendor/assets'
46
+
47
+ VENDOR_ASSETS_STYLESHEETS = 'vendor/assets/stylesheets'
48
+
49
+ VENDOR_ASSETS_JAVASCRIPTS = 'vendor/assets/javascripts'
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,19 @@
1
+ module Commandify
2
+
3
+ module Helpers
4
+
5
+ def log msg
6
+ STDOUT.puts " | " << msg
7
+ end
8
+
9
+ def notify msg
10
+ STDOUT.puts " | " << "\033[1;32m#{msg}\033[m"
11
+ end
12
+
13
+ def error msg
14
+ STDERR.puts " | " << "\033[1;31m#{msg}\033[m"
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,96 @@
1
+ require 'commandify/command'
2
+ require 'commandify/helpers'
3
+ require 'commandify/version'
4
+
5
+ module Commandify
6
+
7
+ module Install
8
+
9
+ class << self
10
+
11
+ include Commandify::Helpers
12
+
13
+ # write to .bashrc if havent already
14
+ def run
15
+ if !File.exists? bashrc
16
+ log 'Creating ~/.bashrc'
17
+ FileUtils.touch bashrc
18
+ end
19
+ if installed?
20
+ error 'Commandify aliases are already installed.'
21
+ else
22
+ run!
23
+ end
24
+ end
25
+
26
+ def run!
27
+ mod_bashrc!
28
+ notify install_message
29
+ end
30
+
31
+ # checks for current Commandify version in .bashrc
32
+ def installed?
33
+ File.read(bashrc).include? start_marker
34
+ end
35
+
36
+ def install_message
37
+ "Be sure to run 'source ~/.bashrc' or open a new terminal for the changes to take effect."
38
+ end
39
+
40
+ # full path of .bashrc
41
+ def bashrc
42
+ File.expand_path('~/.bashrc')
43
+ end
44
+
45
+ # default commandify start marker for .bashrc
46
+ def start_marker
47
+ "# COMMANDIFY #{Commandify::VERSION} #\n"
48
+ end
49
+
50
+ # default commandify end marker for .bashrc
51
+ def end_marker
52
+ "# COMMANDIFY END #\n"
53
+ end
54
+
55
+ # alias string for a single command
56
+ def command_alias command
57
+ "alias #{command}='eval $(bundle exec commandify #{command})'\n"
58
+ end
59
+
60
+ # generates new command aliases
61
+ def new_command_aliases
62
+ aliases = ""
63
+ aliases << start_marker
64
+ Commandify::Command::ALL.each do |command|
65
+ aliases << command_alias(command)
66
+ end
67
+ aliases << end_marker
68
+ end
69
+
70
+ # grabs the old command aliases by start and end markers
71
+ def old_command_aliases
72
+ regex = Regexp.new "^# COMMANDIFY.*#{end_marker}$", Regexp::MULTILINE
73
+ @@old_command_aliases ||= File.read(bashrc).match(regex).to_s
74
+ end
75
+
76
+ # write out aliases to .bashrc
77
+ def mod_bashrc!
78
+ brc = File.read bashrc
79
+ if old_command_aliases.length > 0
80
+ log 'Updating Commandify aliases ...'
81
+ brc.gsub! old_command_aliases, new_command_aliases
82
+ else
83
+ log 'Adding Commandify aliases ...'
84
+ brc << new_command_aliases
85
+ end
86
+ File.open bashrc, 'w' do |file|
87
+ file << brc
88
+ end
89
+ log 'Finished.'
90
+ end
91
+
92
+ end #self
93
+
94
+ end
95
+
96
+ end
@@ -0,0 +1,3 @@
1
+ module Commandify
2
+ VERSION = "0.0.3"
3
+ end
data/lib/commandify.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "commandify/version"
2
+
3
+ module Commandify; end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commandify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - richardcalahan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Commandify your rails app!
15
+ email:
16
+ - richard@calahan.me
17
+ executables:
18
+ - commandify
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/commandify
28
+ - commandify.gemspec
29
+ - lib/commandify.rb
30
+ - lib/commandify/command.rb
31
+ - lib/commandify/core.rb
32
+ - lib/commandify/directories.rb
33
+ - lib/commandify/helpers.rb
34
+ - lib/commandify/install.rb
35
+ - lib/commandify/version.rb
36
+ homepage: ''
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.24
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Amazingly helpful
60
+ test_files: []