terminitor 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,6 +48,10 @@ Once the project file has been declared to your satisfaction, simply execute any
48
48
  This will execute the steps and create the tabs defined and run the various options as expected. That's it. Create as many project files with as many tabs
49
49
  as you would like and automate your workflow.
50
50
 
51
+ If you no longer need a particular project, you can easily remove the yml file for the project:
52
+
53
+ $ terminitor delete foo
54
+
51
55
  You can also see a full list of available projects with:
52
56
 
53
57
  $ terminitor list
@@ -67,7 +71,8 @@ which contains the ideal development setup for OSX. To generate this file, invok
67
71
  $ terminitor create
68
72
 
69
73
  This will generate a 'Termfile' in the current project directory and open the file to be edited in the default text editor. The format
70
- of the file is still YAML as described above in the previous section.
74
+ of the file is still YAML as described above in the previous section. You should *note* that the project directory is automatically
75
+ the working directory for each tab so you can just say `mate .` and the project directory containing the `Termfile` will open.
71
76
 
72
77
  Now, when you or another developer clones a project, you could simply:
73
78
 
@@ -80,6 +85,12 @@ This would clone the project repo, and then install all dependencies and then la
80
85
  this makes assumptions about the user's system setup right now, but we have some ideas on how to make this work more effectively on
81
86
  different configurations in the future.
82
87
 
88
+ In addition, you are in the project folder and you wish to remove the Termfile, you can invoke the command:
89
+
90
+ $ terminitor delete
91
+
92
+ This will clear the `Termfile` for the particular project.
93
+
83
94
  Limitations
84
95
  -----------
85
96
 
data/lib/terminitor.rb CHANGED
@@ -31,7 +31,7 @@ module Terminitor
31
31
  def list
32
32
  say "Global scripts: \n"
33
33
  Dir.glob("#{ENV['HOME']}/.terminitor/*").each do |file|
34
- say " * #{File.basename(file)} #{grab_comment_for_file(file)}"
34
+ say " * #{File.basename(file).gsub('.yml','')} #{grab_comment_for_file(file)}"
35
35
  end
36
36
  end
37
37
 
@@ -41,11 +41,12 @@ module Terminitor
41
41
  end
42
42
 
43
43
  desc "open PROJECT_NAME", "open project yaml"
44
- method_option :root, :type => :string, :default => '.', :aliases => '-r'
44
+ method_option :root, :type => :string, :default => '.', :aliases => '-r'
45
+ method_option :editor, :type => :string, :default => nil, :aliases => '-c'
45
46
  def open(project="")
46
47
  path = resolve_path(project)
47
48
  template "templates/example.yml.tt", path, :skip => true
48
- open_in_editor(path)
49
+ open_in_editor(path,options[:editor])
49
50
  end
50
51
 
51
52
  desc "generate", "create a Termfile in directory"
@@ -54,6 +55,13 @@ module Terminitor
54
55
  invoke :open, [], :root => options[:root]
55
56
  end
56
57
 
58
+ desc "delete PROJECT", "delete project script"
59
+ method_option :root, :type => :string, :default => '.', :aliases => '-r'
60
+ def delete(project="")
61
+ path = resolve_path(project)
62
+ remove_file path
63
+ end
64
+
57
65
  no_tasks do
58
66
 
59
67
  def grab_comment_for_file(file)
@@ -2,8 +2,10 @@ module Terminitor
2
2
  module Runner
3
3
 
4
4
  # opens doc in system designated editor
5
- def open_in_editor(path)
6
- `#{ENV['EDITOR']} #{path}`
5
+ def open_in_editor(path, editor=nil)
6
+ editor = editor || ENV['TERM_EDITOR'] || ENV['EDITOR']
7
+ say "please set $EDITOR or $TERM_EDITOR in your .bash_profile." unless editor
8
+ system("#{editor || 'open'} #{path}")
7
9
  end
8
10
 
9
11
  def do_project(path)
@@ -1,3 +1,3 @@
1
1
  module Terminitor
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -18,8 +18,8 @@ context "Terminitor" do
18
18
  setup { File.open(File.join(@path,'foo.yml'),"w") { |f| f.puts @template } }
19
19
  setup { File.open(File.join(@path,'bar.yml'),"w") { |f| f.puts @template } }
20
20
  setup { capture(:stdout) { Terminitor::Cli.start(['list']) } }
21
- asserts_topic.matches %r{foo.yml - COMMENT OF SCRIPT HERE}
22
- asserts_topic.matches %r{bar.yml - COMMENT OF SCRIPT HERE}
21
+ asserts_topic.matches %r{foo - COMMENT OF SCRIPT HERE}
22
+ asserts_topic.matches %r{bar - COMMENT OF SCRIPT HERE}
23
23
  end
24
24
 
25
25
  context "setup" do
@@ -34,7 +34,7 @@ context "Terminitor" do
34
34
  teardown { `rm -rf /tmp/sample_project` }
35
35
 
36
36
  context "for project yaml" do
37
- setup { mock.instance_of(Terminitor::Cli).open_in_editor("#{ENV['HOME']}/.terminitor/test_foo_bar2.yml") { true }.once }
37
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor("#{ENV['HOME']}/.terminitor/test_foo_bar2.yml",nil) { true }.once }
38
38
  setup { capture(:stdout) { Terminitor::Cli.start(['open','test_foo_bar2']) } }
39
39
  asserts_topic.matches %r{create}
40
40
  asserts_topic.matches %r{test_foo_bar2.yml}
@@ -42,7 +42,7 @@ context "Terminitor" do
42
42
 
43
43
  context "for Termfile" do
44
44
  context "with open" do
45
- setup { mock.instance_of(Terminitor::Cli).open_in_editor("/tmp/sample_project/Termfile") { true }.once }
45
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor("/tmp/sample_project/Termfile",nil) { true }.once }
46
46
  setup { capture(:stdout) { Terminitor::Cli.start(['open','-r=/tmp/sample_project']) } }
47
47
  asserts_topic.matches %r{create}
48
48
  asserts_topic.matches %r{Termfile}
@@ -50,10 +50,68 @@ context "Terminitor" do
50
50
 
51
51
  context "with create" do
52
52
  setup { mock.instance_of(Terminitor::Cli).invoke(:open, [], :root => '/tmp/sample_project') { true }.once }
53
- asserts('calls open') { capture(:stdout) { Terminitor::Cli.start(['create','-r=/tmp/sample_project']) } }
53
+ asserts('calls open') { capture(:stdout) { Terminitor::Cli.start(['create','-r=/tmp/sample_project']) } }
54
54
  end
55
+
56
+ context "with editors" do
57
+ setup { @test_runner = TestRunner.new }
58
+ context "using $EDITOR" do
59
+ setup { ENV['EDITOR'] = 'mate' }
60
+ setup { mock(@test_runner).system("mate /tmp/sample_project/foo.yml").returns {true}.once }
61
+ asserts("calls") { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml") } }
62
+ end
63
+
64
+ context "using $TERM_EDITOR" do
65
+ setup { ENV['TERM_EDITOR'] = 'vim' }
66
+ setup { ENV['EDITOR'] = 'jack' }
67
+ setup { mock(@test_runner).system("vim /tmp/sample_project/foo.yml").returns {true}.once }
68
+ asserts("calls") { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml")} }
69
+ end
70
+
71
+ context "without any editor" do
72
+ setup { ENV['TERM_EDITOR'] = nil }
73
+ setup { ENV['EDITOR'] = nil }
74
+ setup { mock(@test_runner).system("open /tmp/sample_project/foo.yml").returns {true}.once }
75
+ setup { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml")} }
76
+ asserts_topic.matches %r{please set}
77
+ end
78
+
79
+ context "with editor flag" do
80
+ context "open_in_editor takes flag" do
81
+ setup { ENV['TERM_EDITOR'] = 'vim' }
82
+ setup { ENV['EDITOR'] = 'jack' }
83
+ setup { mock(@test_runner).system("nano /tmp/sample_project/foo.yml").returns {true}.once }
84
+ asserts("calls") { capture(:stdout) { @test_runner.open_in_editor("/tmp/sample_project/foo.yml","nano")} }
85
+ end
86
+
87
+ context "thor accepts open -c(editor) flag" do
88
+ setup { FileUtils.mkdir_p('/tmp/sample_project') }
89
+ setup { @path = '/tmp/sample_project/Termfile' }
90
+ setup { File.open(@path,"w") { |f| f.puts @yaml } }
91
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor(@path,'nano') { true }.once }
92
+ asserts("runs nano") { capture(:stdout) { Terminitor::Cli.start(['open','-r=/tmp/sample_project','-c=nano']) } }
93
+ end
94
+ end
95
+
96
+ end
97
+
55
98
  end
56
99
 
100
+ context "delete" do
101
+
102
+ context "directory Termfile" do
103
+ setup { FileUtils.mkdir_p('/tmp/sample_project')}
104
+ setup { FileUtils.touch("/tmp/sample_project/Termfile") }
105
+ setup { capture(:stdout) { Terminitor::Cli.start(['delete',"-r=/tmp/sample_project"]) } }
106
+ asserts("Termfile") { File.exists?("/tmp/sample_project/Termfile") }.not!
107
+ end
108
+
109
+ context "global script" do
110
+ setup { FileUtils.touch("#{ENV['HOME']}/.terminitor/delete_this.yml") }
111
+ setup { capture(:stdout) { Terminitor::Cli.start(['delete','delete_this']) } }
112
+ asserts(" script") { File.exists?("#{ENV['HOME']}/.terminitor/delete_this.yml") }.not!
113
+ end
114
+ end
57
115
 
58
116
 
59
117
  end
data/test/teststrap.rb CHANGED
@@ -27,6 +27,10 @@ end
27
27
 
28
28
  class TestRunner
29
29
  include Terminitor::Runner
30
+
31
+ def say(caption)
32
+ puts caption
33
+ end
30
34
  end
31
35
 
32
36
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminitor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arthur Chiu
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-14 00:00:00 -07:00
19
+ date: 2010-09-16 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency