termup 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,7 +13,7 @@ Installation
13
13
  Usage
14
14
  -----
15
15
 
16
- #### Getting Started ####
16
+ ### Getting Started ###
17
17
 
18
18
  Call the following command:
19
19
 
@@ -27,27 +27,53 @@ And now you're good to go:
27
27
 
28
28
  $ termup start new_project
29
29
 
30
- #### YAML Syntax ####
30
+ ### YAML Syntax ###
31
31
 
32
32
  # ~/.config/termup/new_project.yml
33
33
  ---
34
- - tab1:
35
- - cd ~/foo/bar
36
- - git status
37
- - tab2:
38
- - mysql -u root
39
- - show databases;
40
- - tab3: echo "hello world"
41
- - tab4:
42
- - cd ~/foo/project
43
- - autotest
34
+ tabs:
35
+ - tab1:
36
+ - cd ~/foo/bar
37
+ - git status
38
+ - tab2:
39
+ - mysql -u root
40
+ - show databases;
41
+ - tab3: echo "hello world"
42
+ - tab4:
43
+ - cd ~/foo/project
44
+ - autotest
45
+ options:
46
+ iterm:
47
+ width: 2
48
+ height: 2
44
49
 
45
50
  Tabs can contain a single command, or YAML arrays to execute multiple commands.
46
51
 
47
- #### Shortcut ####
52
+ ### Shortcut ###
48
53
 
49
54
  Commands have a shortcut for even fewer keystrokes.
50
55
 
51
56
  $ termup s new_project
52
57
 
53
58
  That's equivalent to `termup start new_project`.
59
+
60
+ ### iTerm 2 Split Pane Support ###
61
+
62
+ Specify iTerm option to use split pane.
63
+
64
+ options:
65
+ iterm:
66
+ width: 2
67
+ height: 2
68
+
69
+ The setting above turns to:
70
+
71
+ #################
72
+ # # #
73
+ # 1 # 3 #
74
+ # # #
75
+ #################
76
+ # # #
77
+ # 2 # 4 #
78
+ # # #
79
+ #################
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -1,12 +1,17 @@
1
1
  # COMMENT OF SCRIPT HERE
2
2
  ---
3
- - tab1:
4
- - cd ~/foo/bar
5
- - git status
6
- - tab2:
7
- - mysql -u root
8
- - show databases;
9
- - tab3: echo "hello world"
10
- - tab4:
11
- - cd ~/foo/project
12
- - autotest
3
+ tabs:
4
+ - tab1:
5
+ - cd ~/foo/bar
6
+ - git status
7
+ - tab2:
8
+ - mysql -u root
9
+ - show databases;
10
+ - tab3: echo "hello world"
11
+ - tab4:
12
+ - cd ~/foo/project
13
+ - autotest
14
+ options:
15
+ iterm:
16
+ width: 2
17
+ height: 2
data/lib/termup/base.rb CHANGED
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
1
  require 'appscript'
4
2
  require 'yaml'
5
3
 
@@ -8,26 +6,61 @@ module Termup
8
6
  include Appscript
9
7
 
10
8
  def initialize(project)
11
- @terminal = app('Terminal')
12
- tabs = YAML.load(File.read("#{TERMUP_DIR}/#{project}.yml"))
13
- tabs.each do |hash|
9
+ @apps = app("System Events").application_processes
10
+ @frontmost = @apps.get.select{|i| i.frontmost.get }.map{|i| i.name.get }.first
11
+ return unless ["Terminal", "iTerm"].include?(@frontmost)
12
+ @terminal = app(@frontmost)
13
+
14
+ @project = YAML.load(File.read("#{TERMUP_DIR}/#{project}.yml"))
15
+
16
+ # Split panes for iTerm
17
+ split_panes if @frontmost == "iTerm" and @project['options']['iterm']
18
+
19
+ @project['tabs'].each do |hash|
14
20
  tabname = hash.keys.first
15
21
  cmds = hash.values.first
16
22
  cmds = [cmds].flatten
17
23
  tab = new_tab
18
24
  cmds.each do |cmd|
19
- @terminal.do_script(cmd, :in => tab)
25
+ case @frontmost
26
+ when "Terminal"
27
+ @terminal.do_script(cmd, :in => tab)
28
+ when "iTerm"
29
+ @terminal.current_terminal.current_session.write(:text => "#{cmd}")
30
+ end
20
31
  end
21
32
  end
22
33
  end
23
34
 
24
35
  def new_tab
25
36
  if @got_first_tab_already
26
- app("System Events").application_processes["Terminal.app"].keystroke("t", :using => :command_down)
37
+ case @frontmost
38
+ when "Terminal"
39
+ @apps[@frontmost].keystroke("t", :using => :command_down)
40
+ when "iTerm"
41
+ @apps[@frontmost].keystroke("]", :using => :command_down)
42
+ end
27
43
  end
28
44
  @got_first_tab_already = true
29
45
  sleep 0.01 # Allow some time to complete opening a new tab
30
- @terminal.windows[1].tabs.last.get
46
+ @terminal.windows[1].tabs.last.get if @frontmost == "Terminal"
47
+ end
48
+
49
+ def split_panes
50
+ # Virtical splits
51
+ (@project['options']['iterm']['width'] - 1).times do |i|
52
+ @apps[@frontmost].keystroke("d", :using => :command_down)
53
+ end
54
+ # Back to home
55
+ @apps[@frontmost].keystroke("]", :using => :command_down)
56
+ # Horizontal splits
57
+ @project['options']['iterm']['width'].times do |i|
58
+ (@project['options']['iterm']['height'] - 1).times do |i|
59
+ @apps[@frontmost].keystroke("d", :using => [ :command_down, :shift_down ])
60
+ end
61
+ # Move to the right
62
+ @apps[@frontmost].keystroke("]", :using => :command_down)
63
+ end
31
64
  end
32
65
  end
33
66
  end
data/lib/termup/cli.rb CHANGED
@@ -25,6 +25,7 @@ module Termup
25
25
 
26
26
  desc "edit PROJECT", "Edit termup project (Shortcut: e)"
27
27
  def edit(project)
28
+ create(project) unless File.exists?(path(project))
28
29
  say "please set $EDITOR in your .bash_profile." and return unless editor = ENV['EDITOR']
29
30
  system("#{editor} #{path(project)}")
30
31
  end
data/termup.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{termup}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kenn Ejima"]
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: termup
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.1
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kenn Ejima
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- hash: 4478408603716674738
102
+ hash: 1610649593229339461
103
103
  segments:
104
104
  - 0
105
105
  version: "0"