terminitor 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,13 +12,15 @@ Installation
12
12
  Usage
13
13
  -------
14
14
 
15
+ ### Creating Local Projects ###
16
+
15
17
  Using terminitor is quite easy. To define or edit a project file, simply invoke the command:
16
18
 
17
19
  $ terminitor open foo
18
20
 
19
- This will open your default editor (set by the $EDITOR variable in BASH) and you can proceed to define the commands for that project:
21
+ This will open your default editor (set through the $EDITOR variable in BASH) and you can proceed to define the commands for that project:
20
22
 
21
- # ~/.terminit/foo.yml
23
+ # ~/.terminitor/foo.yml
22
24
  # you can make as many tabs as you wish...
23
25
  # tab names are actually arbitrary at this point too.
24
26
  ---
@@ -35,31 +37,76 @@ This will open your default editor (set by the $EDITOR variable in BASH) and you
35
37
  - cd ~/foo/project
36
38
  - autotest
37
39
 
38
- Simply define the tabs and declare each command. Note that the session of each tab is maintained, so you just declare actions here as
39
- you would manually type in the terminal. Note that the title for each tab(namely tab1, tab2) are arbitrary, and can be named whatever you want. They are simply placeholders
40
+ Simply define each tab and declare the commands. Note that the session for each tab is maintained, so you just declare actions here as
41
+ you would manually type in the terminal. Note that the title for each tab(namely tab1, tab2) are arbitrary, and can be named whatever you want.
42
+ They are simply placeholders for the time being for upcoming features.
40
43
 
41
- Once the project file has been declared to your satisfaction, simply execute any project defined in the @.terminit@ directory with:
44
+ Once the project file has been declared to your satisfaction, simply execute any project defined in the `~/.terminitor` directory with:
42
45
 
43
46
  $ terminitor start foo
44
47
 
45
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
46
49
  as you would like and automate your workflow.
47
50
 
51
+ You can also see a full list of available projects with:
52
+
53
+ $ terminitor list
54
+
55
+ This will print out the available project files that you can execute.
56
+
57
+ ### Creating Termfile for Repo ###
58
+
59
+ In addition to creating 'local' projects which can run on your computer (and are stored in your home directory), we also
60
+ optionally allow you to create a `Termfile` within any directory and then you can execute this any time to setup the
61
+ environment for that particular project source.
62
+
63
+ For example, let's say I am in `/code/my/foo/project` directory which is
64
+ a Sinatra application. This application might have a `Gemfile` which includes all dependencies. You can also generate a `Termfile`
65
+ which contains the ideal development setup for OSX. To generate this file, invoke:
66
+
67
+ $ terminitor create
68
+
69
+ 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.
71
+
72
+ Now, when you or another developer clones a project, you could simply:
73
+
74
+ $ git clone git://path/to/my/foo/project.git
75
+ $ cd project
76
+ $ bundle install
77
+ $ terminitor start
78
+
79
+ This would clone the project repo, and then install all dependencies and then launch the ideal development environment for the project. Clearly
80
+ 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
+ different configurations in the future.
82
+
48
83
  Limitations
49
84
  -----------
50
85
 
51
86
  This only works on OS X because of the dependency on applescript. It would presumably not be impossible to port this to Linux or Windows, and
52
87
  of course patches and suggestions are welcome.
53
88
 
89
+ Another issue is that right now tabs are created by invoking keystrokes which means there are limitations with the terminal being in
90
+ focus during execution of these commands. Obviously the long term goal is to solve this issue as well but in all honesty,
91
+ this solution works well enough most of the time.
92
+
54
93
  Authors
55
94
  -------
56
95
 
57
- The core code was adapted before by Nathan Esquenazi and Thomas Shafer. In September 2010, Arthur Chiu and Nathan Esquenazi gemified and released this to gemcutter.
96
+ The core code was adapted before by Nathan Esquenazi and Thomas Shafer.
97
+ In September 2010, Arthur Chiu and Nathan Esquenazi gemified and released this to gemcutter.
98
+
99
+ Contributors
100
+ -------------
101
+
102
+ Thanks to the following people for their contributions so far:
103
+
104
+ * Pat George ([pcg79](http://github.com/pcg79)) for contributing a patch for when a project is not found.
58
105
 
59
106
  Acknowledgements
60
107
  -----------------
61
108
 
62
- This code came originally years ago from: http://blog.elctech.com/2008/01/16/script-terminal-with-terminit/ .
109
+ This code came originally years ago from: [ELCTech](http://blog.elctech.com/2008/01/16/script-terminal-with-terminit/).
63
110
  This was a great start and made terminal automation easy. However, the repository is dead, but we had continued using the code for a while.
64
111
  Finally, we decided the time had come to release this code back to the world as a gem. Thanks to ELC for creating the original
65
112
  source for this project.
@@ -0,0 +1,16 @@
1
+ # COMMENT OF SCRIPT HERE
2
+ # you can make as many tabs as you wish...
3
+ # tab names are actually arbitrary at this point too.
4
+ ---
5
+ - tab1:
6
+ - cd ~/foo/bar
7
+ - gitx
8
+ - tab2:
9
+ - mysql -u root
10
+ - use test;
11
+ - show tables;
12
+ - tab3: echo "hello world"
13
+ - tab4: cd ~/baz/ && git pull
14
+ - tab5:
15
+ - cd ~/foo/project
16
+ - autotest
data/lib/terminitor.rb CHANGED
@@ -10,9 +10,28 @@ module Terminitor
10
10
  include Terminitor::Runner
11
11
  include Appscript
12
12
 
13
+ def self.source_root; File.dirname(__FILE__); end
14
+
13
15
  desc "start PROJECT_NAME", "runs the terminitor project"
14
- def start(project)
15
- do_project(project)
16
+ method_option :root, :type => :string, :default => '.', :aliases => '-r'
17
+ def start(project="")
18
+ path = resolve_path(project)
19
+ if File.exists?(path)
20
+ do_project(path)
21
+ else
22
+ if project
23
+ say "'#{File.basename(path)}' doesn't exist! Please run 'terminitor open #{project}'"
24
+ else
25
+ say "Termfile doesn't exist! Please run 'terminitor open' in project directory"
26
+ end
27
+ end
28
+ end
29
+
30
+ desc "list", "lists all terminitor scripts"
31
+ def list
32
+ Dir.glob("#{ENV['HOME']}/.terminitor/*").each do |file|
33
+ say "#{File.basename(file)} - #{File.read(file).first.gsub("#",'')}"
34
+ end
16
35
  end
17
36
 
18
37
  desc "setup", "create initial root terminitor folder"
@@ -21,10 +40,18 @@ module Terminitor
21
40
  end
22
41
 
23
42
  desc "open PROJECT_NAME", "open project yaml"
24
- def open(project)
25
- path = "#{ENV['HOME']}/.terminitor/#{project}.yml"
26
- create_file path, :skip => true
43
+ method_option :root, :type => :string, :default => '.', :aliases => '-r'
44
+ def open(project="")
45
+ path = resolve_path(project)
46
+ template "templates/example.yml.tt", path, :skip => true
27
47
  open_in_editor(path)
28
48
  end
49
+
50
+ desc "generate", "create a Termfile in directory"
51
+ method_option :root, :type => :string, :default => '.', :aliases => '-r'
52
+ def create
53
+ invoke :open, [], :root => options[:root]
54
+ end
55
+
29
56
  end
30
57
  end
@@ -6,9 +6,10 @@ module Terminitor
6
6
  `#{ENV['EDITOR']} #{path}`
7
7
  end
8
8
 
9
- def do_project(project)
9
+ def do_project(path)
10
10
  terminal = app('Terminal')
11
- tabs = load_config(project)
11
+ tabs = load_config(path)
12
+
12
13
  tabs.each do |hash|
13
14
  tabname = hash.keys.first
14
15
  cmds = hash.values.first
@@ -21,20 +22,15 @@ module Terminitor
21
22
  end
22
23
  end
23
24
 
24
- # def usage
25
- # puts "
26
- # Usage:
27
- # #{File.basename(@file)} project_name
28
- # where project_name is the name of a terminit project yaml file
29
- #
30
- # See the README for more information.
31
- # "
32
- # exit 0
33
- # end
25
+ def resolve_path(project)
26
+ unless project.empty?
27
+ File.join(ENV['HOME'],'.terminitor', "#{project.sub(/\.yml$/, '')}.yml")
28
+ else
29
+ File.join(options[:root],"Termfile")
30
+ end
31
+ end
34
32
 
35
- def load_config(project)
36
- path = File.join(ENV['HOME'],'.terminitor', "#{project.sub(/\.yml$/, '')}.yml")
37
- return false unless File.exists?(path)
33
+ def load_config(path)
38
34
  YAML.load(File.read(path))
39
35
  end
40
36
 
@@ -51,15 +47,17 @@ module Terminitor
51
47
  app("System Events").application_processes["Terminal.app"].keystroke("t", :using => :command_down)
52
48
  end
53
49
  @got_first_tab_already = true
54
- local_window = terminal.windows[terminal.windows.count - 1]
50
+ local_window = active_window(terminal)
55
51
  local_tabs = local_window.tabs if local_window
56
52
  local_tabs.last.get if local_tabs
57
53
  end
58
-
59
- # checks to see if the user has Visor installed
60
- def has_visor?
61
- File.exists?("#{ENV['HOME']}/Library/Application\ Support/SIMBL/Plugins/Visor.bundle/")
54
+
55
+ # makes sure to set active window as frontmost.
56
+ def active_window(terminal)
57
+ (1..terminal.windows.count).each do |i|
58
+ window = terminal.windows[i]
59
+ return window if window.properties_.get[:frontmost]
60
+ end
62
61
  end
63
-
64
62
  end
65
63
  end
@@ -1,3 +1,3 @@
1
1
  module Terminitor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/terminitor.gemspec CHANGED
@@ -20,7 +20,15 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency "riot", "~>0.14.0"
21
21
  s.add_development_dependency "rr"
22
22
  s.add_development_dependency "fakefs"
23
+ s.post_install_message = %q{********************************************************************************
23
24
 
25
+ Terminitor is installed!
26
+ Please run 'terminitor setup'.
27
+ This will create a directory at ~/.terminitor which will hold all your global scripts.
28
+ Thanks!
29
+
30
+ ********************************************************************************
31
+ }
24
32
  s.files = `git ls-files`.split("\n")
25
33
  s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
26
34
  s.require_path = 'lib'
@@ -1,18 +1,9 @@
1
1
  # you can make as many tabs as you wish...
2
2
  # tab names are actually arbitrary at this point too.
3
3
  ---
4
-
5
- - workflow:
6
- - default:
7
- - cd /path/to/
8
- - gitx
9
- - padrino:
10
- - cd /padrino/app
11
- - padrino start
12
- - project:
13
- - tab1:
14
- - cd /foo/bar
15
- - gitx
16
- - tab2:
17
- - ls
18
- - mate .
4
+ - tab1:
5
+ - cd /foo/bar
6
+ - gitx
7
+ - tab2:
8
+ - ls
9
+ - mate .
@@ -2,6 +2,7 @@ require File.expand_path('../teststrap',__FILE__)
2
2
 
3
3
  context "Terminitor" do
4
4
  setup { @yaml = File.read(File.expand_path('../fixtures/foo.yml', __FILE__)) }
5
+ setup { @template = File.read(File.expand_path('../../lib/templates/example.yml.tt', __FILE__)) }
5
6
  setup { FakeFS.activate! }
6
7
  teardown { FakeFS.deactivate! }
7
8
 
@@ -12,32 +13,82 @@ context "Terminitor" do
12
13
  asserts_topic.matches %r{open PROJECT_NAME}
13
14
  end
14
15
 
16
+ context "list" do
17
+ setup { @path = "#{ENV['HOME']}/.terminitor/" }
18
+ setup { File.open(File.join(@path,'foo.yml'),"w") { |f| f.puts @template } }
19
+ setup { File.open(File.join(@path,'bar.yml'),"w") { |f| f.puts @template } }
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}
23
+ end
24
+
15
25
  context "setup" do
16
26
  setup { capture(:stdout) { Terminitor::Cli.start(['setup']) } }
17
27
  asserts("creates .terminitor") { File.exists?("#{ENV['HOME']}/.terminitor") }
18
28
  end
19
29
 
20
30
  context "open" do
21
- setup { mock.instance_of(Terminitor::Cli).open_in_editor("#{ENV['HOME']}/.terminitor/foo.yml") { true }.once }
22
- setup { capture(:stdout) { Terminitor::Cli.start(['open','foo']) } }
23
- asserts_topic.matches %r{create}
31
+ setup { FakeFS.deactivate! }
32
+ setup { `rm -rf #{ENV['HOME']}/.terminitor/test_foo_bar2.yml`}
33
+
34
+ teardown { `rm -rf /tmp/sample_project` }
35
+
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 }
38
+ setup { capture(:stdout) { Terminitor::Cli.start(['open','test_foo_bar2']) } }
39
+ asserts_topic.matches %r{create}
40
+ asserts_topic.matches %r{test_foo_bar2.yml}
41
+ end
42
+
43
+ context "for Termfile" do
44
+ context "with open" do
45
+ setup { mock.instance_of(Terminitor::Cli).open_in_editor("/tmp/sample_project/Termfile") { true }.once }
46
+ setup { capture(:stdout) { Terminitor::Cli.start(['open','-r=/tmp/sample_project']) } }
47
+ asserts_topic.matches %r{create}
48
+ asserts_topic.matches %r{Termfile}
49
+ end
50
+
51
+ context "with create" do
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']) } }
54
+ end
55
+ end
56
+
57
+
58
+
24
59
  end
25
60
 
26
61
  context "start" do
27
- setup do
28
- @test_item = TestItem.new
29
- @test_runner = TestRunner.new
30
- stub(@test_runner).open_tab(anything) { true }.twice
31
- mock(@test_item).do_script('cd /foo/bar', anything) { true }.once
32
- mock(@test_item).do_script('gitx', anything) { true }.once
33
- mock(@test_item).do_script('ls', anything) { true }.once
34
- mock(@test_item).do_script('mate .', anything) { true }.once
35
- stub(@test_runner).app('Terminal') { TestObject.new(@test_item) }
62
+
63
+ context "for project yaml" do
64
+ setup do
65
+ @test_item = TestItem.new
66
+ @test_runner = TestRunner.new
67
+ stub(@test_runner).open_tab(anything) { true }.twice
68
+ mock(@test_item).do_script('cd /foo/bar', anything) { true }.once
69
+ mock(@test_item).do_script('gitx', anything) { true }.once
70
+ mock(@test_item).do_script('ls', anything) { true }.once
71
+ mock(@test_item).do_script('mate .', anything) { true }.once
72
+ stub(@test_runner).app('Terminal') { TestObject.new(@test_item) }
73
+ end
74
+ setup { capture(:stdout) { Terminitor::Cli.start(['setup']) } }
75
+ setup { @path = "#{ENV['HOME']}/.terminitor/foo.yml" }
76
+ setup { File.open(@path,"w") { |f| f.puts @yaml } }
77
+ asserts("runs project") { @test_runner.do_project(@path) }
36
78
  end
37
- setup { capture(:stdout) { Terminitor::Cli.start(['setup']) } }
38
- setup { File.open("#{ENV['HOME']}/.terminitor/foo.yml","w") { |f| f.puts @yaml } }
39
- asserts("runs project") { @test_runner.do_project("foo") }
40
- end
41
79
 
80
+ context "for Termfile" do
81
+ setup { FileUtils.mkdir_p('/tmp/sample_project') }
82
+ setup { @path = '/tmp/sample_project/Termfile' }
83
+ setup { File.open(@path,"w") { |f| f.puts @yaml } }
84
+ setup { mock.instance_of(Terminitor::Cli).do_project(@path) { true }.once }
85
+ asserts("runs .terminit") { capture(:stdout) { Terminitor::Cli.start(['start','-r=/tmp/sample_project']) } }
86
+ end
87
+
88
+ context "with invalid project" do
89
+ setup { capture(:stdout) { Terminitor::Cli.start(['start','nonono']) } }
90
+ asserts_topic.matches %r{'nonono.yml' doesn't exist! Please run 'terminitor open nonono'}
91
+ end
42
92
 
93
+ end
43
94
  end
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Arthur Chiu
@@ -125,6 +125,7 @@ files:
125
125
  - README.md
126
126
  - Rakefile
127
127
  - bin/terminitor
128
+ - lib/templates/example.yml.tt
128
129
  - lib/terminitor.rb
129
130
  - lib/terminitor/runner.rb
130
131
  - lib/terminitor/version.rb
@@ -136,7 +137,8 @@ has_rdoc: true
136
137
  homepage: http://rubygems.org/gems/terminitor
137
138
  licenses: []
138
139
 
139
- post_install_message:
140
+ post_install_message: "********************************************************************************\n\n Terminitor is installed! \n Please run 'terminitor setup'. \n This will create a directory at ~/.terminitor which will hold all your global scripts.\n Thanks!\n\n\
141
+ ********************************************************************************\n "
140
142
  rdoc_options: []
141
143
 
142
144
  require_paths: