ro_commands 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/bin/ro_client +1 -0
  4. data/bin/ro_server +1 -1
  5. data/config/rorc.rb +1 -0
  6. data/lib/bash_builder.rb +10 -7
  7. data/lib/bash_builder_helper.rb +25 -23
  8. data/lib/bash_templates/file.sh +1 -0
  9. data/lib/bash_templates/git.sh +1 -0
  10. data/lib/bash_templates/jekyll.sh +3 -0
  11. data/lib/bash_templates/misc.sh +6 -39
  12. data/lib/bash_templates/ruby.sh +1 -0
  13. data/lib/bash_templates/rubymine_idea.sh +41 -0
  14. data/lib/bash_templates/shortcuts.sh +1 -1
  15. data/lib/bash_templates/video.sh +4 -0
  16. data/lib/builder_templates/set_envs.erb +3 -2
  17. data/lib/drb/client.rb +14 -4
  18. data/lib/drb/server.rb +2 -1
  19. data/lib/git_flow_builder_helper.rb +24 -22
  20. data/lib/rails_builder_helper.rb +31 -28
  21. data/lib/ro_commands/base.rb +13 -2
  22. data/lib/ro_commands/core_ext/string.rb +4 -0
  23. data/lib/ro_commands/core_ext/thor.rb +0 -71
  24. data/lib/ro_commands/dsl/{file.rb → ro_file.rb} +3 -4
  25. data/lib/ro_commands/generators/spec_file.rb +24 -17
  26. data/lib/ro_commands/generators/templates/ex.erb +4 -0
  27. data/lib/ro_commands/generators/templates/spec.erb +3 -0
  28. data/lib/ro_commands/helpers/bash.rb +33 -7
  29. data/lib/ro_commands/helpers/out.rb +61 -2
  30. data/lib/ro_commands/info.rb +12 -8
  31. data/lib/ro_commands/navigate.rb +5 -1
  32. data/lib/ro_commands/rails.rb +1 -1
  33. data/lib/ro_commands/shortcuts.rb +82 -3
  34. data/lib/ro_commands/try.rb +8 -1
  35. data/lib/ro_commands/version.rb +1 -1
  36. data/lib/ro_commands/zeus_templates/custom_plan.rb +15 -7
  37. data/lib/ro_commands/zeus_templates/zeus.json +12 -5
  38. data/lib/set_envs_helper.rb +70 -0
  39. data/ro_commands.sh +839 -0
  40. metadata +66 -5
  41. data/lib/shortcuts.rb +0 -43
@@ -2,6 +2,8 @@ require 'fileutils'
2
2
  require_relative "base_generator"
3
3
  require "erb"
4
4
  require "find"
5
+ require "ro_commands/core_ext/string"
6
+ require "active_support"
5
7
  module RoCommands
6
8
  module Generators
7
9
  class SpecFile
@@ -29,34 +31,39 @@ module RoCommands
29
31
  def get_df
30
32
  if name
31
33
  f = File.basename name
32
- r = name.split("/")
33
- d = (r - [f]).join("/")
34
+ d = name.split("/").first
34
35
  end
35
36
  return d, f
36
37
  end
37
38
 
39
+ def constant_name
40
+ if path
41
+ r = File.basename(path).gsub(%r{_spec\.rb}) do |m|
42
+ ""
43
+ end
44
+
45
+ r.camelize
46
+ end
47
+ end
48
+
38
49
  def path
39
50
  d, f = get_df
40
51
  #puts "d:#{d} line:#{__LINE__}"
41
52
  if test(?d, 'lib')
42
- dir_full_path = Find.find('lib').select do |file|
53
+ lib_dirs = Find.find('lib').select do |file|
43
54
  test(?d, file)
44
- end.select do |dir|
45
- basename = File.basename dir
46
-
47
- #puts "basename:#{basename} line:#{__LINE__}"
48
- basename.match(%r{^#{d.split("").join(".*")}})
49
- end.first
50
-
51
- #puts "dir_full_path:#{dir_full_path} line:#{__LINE__}"
52
-
53
- files = Dir[File.join(dir_full_path, '**')].select do |file|
54
- basename = File.basename file
55
- test(?f, file) and basename.match(%r{^#{f}})
56
55
  end
56
+ dir_full_path = lib_dirs.grep(%r{#{d.implicit}$}).first || 'lib'
57
+ files = Find.find(dir_full_path).select do |file|
58
+ if test(?f, file)
59
+ basename = File.basename file
60
+ basename.match(%r{^#{f.implicit}})
61
+ end
62
+ end
63
+
57
64
  file = files.first.gsub(%r{\.rb}, "")
58
- file = File.basename(file)
59
- File.join(dir, dir_full_path, "#{file}_spec.rb")
65
+ basename = File.basename(file)
66
+ File.join(dir, dir_full_path, "#{basename}_spec.rb")
60
67
  end
61
68
  end
62
69
 
@@ -28,3 +28,7 @@ module M
28
28
  end
29
29
  end
30
30
  end
31
+
32
+ module M2
33
+
34
+ end
@@ -1,2 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe "<%= constant_name %>" do
4
+
5
+ end
@@ -1,17 +1,43 @@
1
1
  require_relative "out"
2
+ require "open3"
2
3
  module Bash
4
+ class << self
5
+ def status
6
+ @@status ||= nil
7
+ end
8
+
9
+ def out
10
+ @@out ||= nil
11
+ end
12
+
13
+ def err
14
+ @@err ||= nil
15
+ end
16
+ end
17
+
3
18
  def _bash(cmd)
4
19
  cmd = handle_path(cmd)
5
- result = `#{cmd}`
6
- Out.out result
20
+ Out.out("Running: #{cmd}")
21
+ @@out, @@err, @@status = Open3.capture3(cmd)
22
+ Out.out @@out
23
+ Out.out @@err
24
+ @@status
7
25
  end
8
26
 
9
- def handle_path(cmd)
10
- r = cmd[/\/(\w|\/)*/]
11
- if r
12
- cmd.gsub! r, "\'#{r}\'"
27
+ # bash capture cmds result
28
+ def bashc(*cmds)
29
+ bash(*cmds)
30
+ if @@status.success?
31
+ @@out
13
32
  else
14
- cmd
33
+ @@err
34
+ end
35
+ end
36
+
37
+ def handle_path(cmd)
38
+ path = %r{\w*/(\w|/|-)+}
39
+ r = cmd.gsub(path) do |m|
40
+ "\'#{m}\'"
15
41
  end
16
42
  end
17
43
 
@@ -1,11 +1,70 @@
1
+ require "fileutils"
2
+ require "term/ansicolor"
1
3
  class Out
2
4
  class << self
3
- def out(msg)
5
+ include ::Term::ANSIColor
6
+
7
+ def out(msg, color=nil)
4
8
  m = msg
5
- puts m
9
+ if color
10
+ puts send(color.to_sym, m)
11
+ else
12
+ puts m
13
+ end
14
+ #write_tmp(m)
6
15
  msgs << m
7
16
  end
8
17
 
18
+ def write_tmp(ctn)
19
+ if save?
20
+ unless ctn.match(%r{^\s*$})
21
+ tmp_ctn = tmp
22
+ tmp_ctn << "At #{Time.now}"
23
+ tmp_ctn << ctn
24
+ File.write(tmp_path, tmp_ctn.join("\n"))
25
+ end
26
+ else
27
+ if test(?s, tmp_path) and test(?s, tmp_path) > 10_000
28
+ FileUtils.rm_f(tmp_path)
29
+ end
30
+ end
31
+ end
32
+
33
+ def save?
34
+ @save
35
+ end
36
+
37
+ def save_on
38
+ File.write(tmp_path, "save_on at #{Time.now}")
39
+ @save = true
40
+ end
41
+
42
+ def save_off
43
+ File.write(tmp_path, "save_on at #{Time.now}")
44
+
45
+ @save = false
46
+ end
47
+
48
+ def save
49
+ @save ||= false
50
+ end
51
+
52
+ def tmp_path
53
+ FileUtils.touch "/tmp/ro_out"
54
+ @tmp_path ||= "/tmp/ro_out"
55
+ end
56
+
57
+ def tmp
58
+ if test(?f, tmp_path)
59
+ File.readlines(tmp_path).delete_if do |l|
60
+ l.blank?
61
+ end
62
+ else
63
+ FileUtils.touch tmp_path
64
+ []
65
+ end
66
+ end
67
+
9
68
  def reset
10
69
  @msgs = []
11
70
  end
@@ -1,7 +1,7 @@
1
- require_relative "dsl/file"
1
+ require_relative "dsl/ro_file"
2
2
  module RoCommands
3
3
  class Info < Base
4
- include DSL::File
4
+ include DSL::RoFile
5
5
 
6
6
  class RoFile
7
7
  def initialize(path, size)
@@ -18,13 +18,13 @@ module RoCommands
18
18
  end
19
19
 
20
20
  def to_s
21
- "size:#{size}, path:#{path}"
21
+ "size:#{(size/1024)}kb, path:#{path}"
22
22
  end
23
23
  end
24
24
 
25
25
  desc 'file_size', ''
26
26
 
27
- def file_size(path, recursive=false)
27
+ def list(path, recursive=false)
28
28
  if recursive
29
29
  find(path).each do |f|
30
30
  files << RoFile.new(f, size(f))
@@ -33,15 +33,17 @@ module RoCommands
33
33
  else
34
34
  Dir[File.join(path, "**")].each do |f|
35
35
  if dir?(f)
36
- s = find(f).inject(0) { |total_size, file_size| total_size += size(f) }
36
+ s = find(f).inject(0) do |total_size, file|
37
+ total_size += size(file).to_i
38
+ end
39
+
37
40
  rf = RoFile.new(f, s)
38
41
  else
39
42
  rf = RoFile.new(f, size(f))
40
43
  end
41
44
  files << rf
42
45
  end
43
-
44
- puts files.sort_by(&:size)
46
+ puts files.compact.sort_by(&:size)
45
47
  end
46
48
  end
47
49
 
@@ -49,7 +51,9 @@ module RoCommands
49
51
  private
50
52
 
51
53
  def files
52
- @files ||= []
54
+ @files.flatten! if defined?(@files) and @files.respond_to?(:flatten!)
55
+ @files.uniq! if defined?(@files) and @files.respond_to?(:uniq!)
56
+ @files ||= []
53
57
  end
54
58
  end
55
59
  end
@@ -1,4 +1,7 @@
1
1
  require "ro_commands/helpers/out"
2
+ require_relative "base"
3
+ require "config/rorc"
4
+
2
5
  module RoCommands
3
6
  class Navigate < Base
4
7
 
@@ -8,7 +11,8 @@ module RoCommands
8
11
  Find.find(File.join(ENV['HOME'], 'Dropbox')) do |f|
9
12
  if test(?d, f)
10
13
  if File.basename(f).match /^#{name}/
11
- puts f
14
+ Out.reset
15
+ Out.out f
12
16
  return
13
17
  end
14
18
  end
@@ -195,7 +195,7 @@ module RoCommands
195
195
  files = files.map do |f|
196
196
  File.basename(f).gsub(%r{\.(\w|\.)+$}, "")
197
197
  end
198
- puts files
198
+ Out.out(files)
199
199
  files
200
200
  end
201
201
  end
@@ -1,3 +1,21 @@
1
+ # this file shortcuts customized by me, so if you wanna use it, please specific your keymap, or download my rubymine settings in github
2
+
3
+ # default shortcuts
4
+ # guake:
5
+ # show/hide guake: f10
6
+ # new tab: ctrl+t
7
+ # close tab: ctrl+w
8
+ # rename tab: f10
9
+
10
+ # rubymine:
11
+ # move to opposite group: ctrl+alt+shift+p
12
+ # move to next splitter: ctrl+alt+shift+t
13
+ # Test: ctrl+shift+t
14
+
15
+ # ln -s $rubymine_path /usr/bin/rubymine
16
+
17
+ require "ro_commands/helpers/bash"
18
+
1
19
  module RoCommands
2
20
  class Shortcuts < Base
3
21
 
@@ -10,22 +28,83 @@ module RoCommands
10
28
  bx "guard"
11
29
  end
12
30
 
31
+ desc usage("lib_spec"), "show lib file in rubymine one splitter and show spec file in rubymine another splitter"
32
+
33
+ def lib_spec
34
+ hide_guake
35
+ push_to_opposite
36
+ next_splitter
37
+ sleep 0.1
38
+ switch_btw_lib_and_spec
39
+ end
40
+
41
+ desc usage("action"), ""
42
+
43
+ desc usage("open_ro_commands"), ""
44
+
45
+ def open_ro_commands
46
+ open_project("ro_commands")
47
+ end
48
+
49
+ desc usage("open_ro_support"), ""
50
+
51
+ def open_ro_support
52
+ open_project("ro_support")
53
+ end
54
+
13
55
  private
14
56
 
57
+ def open_guard
58
+ cmd("bundle exec guard")
59
+ end
60
+
61
+ def open_project(name)
62
+ new_tab
63
+ cd_project(bashc "ro_client navigate get_project #{name}")
64
+ open_guard
65
+ new_tab
66
+ change_tab_name(name)
67
+ rubymine
68
+ end
69
+
70
+ def rubymine
71
+ cmd("rubymine .")
72
+ end
73
+
74
+ def cd_project(name)
75
+ cmd("cd #{name}")
76
+ end
77
+
78
+ def hide_guake
79
+ key "f10"
80
+ end
81
+
82
+ def switch_btw_lib_and_spec
83
+ key "ctrl+shift+t"
84
+ end
85
+
86
+ def push_to_opposite
87
+ key "ctrl+shift+alt+p"
88
+ end
89
+
90
+ def next_splitter
91
+ key "ctrl+shift+alt+t"
92
+ end
93
+
15
94
  def bx(cmd)
16
95
  action "bundle exec #{cmd}"
17
96
  end
18
97
 
19
98
  def action(cmd, postpone=0.012)
20
- a_action(cmd)
99
+ cmd(cmd, postpone)
21
100
  change_tab_name(cmd)
22
101
  new_tab
23
- sleep postpone
24
102
  end
25
103
 
26
- def a_action(name)
104
+ def cmd(name, postpone=0.012)
27
105
  type name
28
106
  enter
107
+ sleep 0.012
29
108
  end
30
109
 
31
110
  def change_tab_name(name)
@@ -2,10 +2,17 @@ require_relative "base"
2
2
 
3
3
  module RoCommands
4
4
  class Try < Base
5
- desc usage("try"), ""
5
+ desc usage("try_meth"), ""
6
6
 
7
7
  def try_meth(*args)
8
8
  Out.out "puts try_meth args:#{args.flatten}"
9
+ Out.out "ENV['WORKING']:#{ENV['WORKING']} file:#{File.basename __FILE__} line:#{__LINE__}"
10
+ end
11
+
12
+ desc usage("pwd"), ""
13
+
14
+ def pwd
15
+ Out.out(Dir.pwd)
9
16
  end
10
17
  end
11
18
  end
@@ -1,3 +1,3 @@
1
1
  module RoroCommands
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,17 +1,25 @@
1
1
  require 'zeus/rails'
2
+ require "active_support"
2
3
  require "ro_commands/rails"
4
+ require "ro_commands/shortcuts"
5
+ require "ro_commands/generate"
3
6
 
4
7
  class CustomPlan < Zeus::Rails
8
+ class << self
9
+ def invoke(name)
10
+ name = File.basename(file).gsub(%r{(.+)\.rb}) do |m|
11
+ ""
12
+ end
5
13
 
6
- def rails
7
- RoCommands::Rails.start
14
+ klass = name.camelize
15
+ define_method(:"#{name}") do |*args|
16
+ RoCommands.const_get(klass.to_sym).start
17
+ end
18
+ end
8
19
  end
9
- # def my_custom_command
10
- # # see https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
11
- # end
12
20
 
13
- def git_flow
14
- RoCommands::GitFlow.start
21
+ %w(rails shortcuts generate).each do |name|
22
+ invoke name
15
23
  end
16
24
  end
17
25
 
@@ -5,9 +5,12 @@
5
5
  "boot": {
6
6
  "default_bundle": {
7
7
  "development_environment": {
8
- "rails":["rails"],
9
- "git_flow":["git_flow"],
10
- "prerake": {"rake": []},
8
+ "rails": ["rails"],
9
+ "shortcuts": ["shortcuts"],
10
+ "generate": ["generate"],
11
+ "prerake": {
12
+ "rake": []
13
+ },
11
14
  "console": ["c"],
12
15
  "server": ["s"],
13
16
  "generate": ["g"],
@@ -15,8 +18,12 @@
15
18
  "dbconsole": []
16
19
  },
17
20
  "test_environment": {
18
- "cucumber_environment": {"cucumber": []},
19
- "test_helper": {"test": ["rspec", "testrb"]}
21
+ "cucumber_environment": {
22
+ "cucumber": []
23
+ },
24
+ "test_helper": {
25
+ "test": ["rspec", "testrb"]
26
+ }
20
27
  }
21
28
  }
22
29
  }
@@ -0,0 +1,70 @@
1
+ require "active_support/concern"
2
+ require "find"
3
+ $root = File.expand_path("../../", __FILE__)
4
+ $lib = File.join($root, 'lib')
5
+ $LOAD_PATH.unshift $root
6
+ $LOAD_PATH.unshift $lib
7
+ require "ro_commands/helpers/bash"
8
+
9
+ module RoHelpers
10
+
11
+ module SetEnvsHelper
12
+ extend ActiveSupport::Concern
13
+
14
+ included do
15
+ end
16
+
17
+ module ClassMethods
18
+ include Bash
19
+
20
+ def bin_ruby
21
+ File.join(ENV['HOME'], ".rbenv/versions/", rb_ver, "/bin/ruby")
22
+ end
23
+
24
+ def bashrc
25
+ File.join(gem, 'ro_commands.sh')
26
+ end
27
+
28
+ def get_bin(bin)
29
+ #Dir.chdir File.join($root)
30
+ #bash "rake install"
31
+ rbenv(bin)
32
+ end
33
+
34
+ def ro_client
35
+ get_bin("ro_client")
36
+ end
37
+
38
+ def ro_server
39
+ get_bin("ro_server")
40
+ end
41
+
42
+ def rbenv(bin)
43
+ File.join(gem, "/bin/#{bin}")
44
+ end
45
+
46
+ def gem
47
+ File.join(ENV['HOME'], ".rbenv/versions/", rb_ver, "lib/ruby/gems/#{RUBY_VERSION}/gems/", gem_ver)
48
+ end
49
+
50
+ def rb_ver
51
+ r = bashc("ruby -v").match(%r{\d.\d.\dp\d+})[0]
52
+ r.gsub(%r{p}) do |m|
53
+ "-p"
54
+ end
55
+
56
+ end
57
+
58
+ def rb_ver_num
59
+ if rb_ver
60
+ rb_ver.match(%r{\d+\.\d+\.\d+})[0]
61
+ end
62
+ end
63
+
64
+ def gem_ver
65
+ r = bashc("gem list ro_commands").match(%r{\((?<version>\d.\d.\d)\)})[:version]
66
+ "ro_commands-#{r}"
67
+ end
68
+ end
69
+ end
70
+ end