teamocil 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 091deeb28007d69a9455c585912c8b3d221cc319
4
- data.tar.gz: 1967badb6034dcc1863a8cc7bc2389134d9fc4b0
3
+ metadata.gz: 7dcef230e6b52430c6fd283000e6ecffd28e45d9
4
+ data.tar.gz: 6359ec6cb545a88e2325f16449d07302f346fb6a
5
5
  SHA512:
6
- metadata.gz: e75c6ee981986b7aa1a7acba303bd513ce32a824041b1b90b4f35efc8f0f6911f3ef723692362fd34b68d120e373cb9d9ab198d502f81bec82f07d3d795c65c9
7
- data.tar.gz: 6bd7bb1932a23ac163f2fca2f7b4b716739dc8cd7c42bc0c2ea932abcc96b7c3d5c2b3352aadaa5c18a6d5f12ab9e5fdae075d1e445dd040761a927b3794adf4
6
+ metadata.gz: e80f9d9750d444a6323d146d48c074f33dde63fd0cdf7e674d924fb03d72912109f8092eac2fd98a83e07f64d5c259173d859b05ba38a05018370ed4624c095e
7
+ data.tar.gz: 3e90ff56c60c676f8616f33b896849bc4c912d3878f11af411b0845f6dc3caaa30b460716f8afc80b1f3d1787e943a403af5913eee6b5f9f24355798896c1adb
data/README.md CHANGED
@@ -60,8 +60,11 @@ The downside of that is that several features were dropped during the rewrite
60
60
  process, mostly because I didn’t actually use/need them and I got tired of
61
61
  maintaining features I don’t think are useful.
62
62
 
63
- But hey, that’s just my opinion. Feel free to fork the repository and add as
64
- many features as you want :smile:.
63
+ You *might* have to clean up your layout files after upgrading to 1.0. I’m
64
+ sorry about that. The documentation in `README.md` should help you find which
65
+ keys are now supported.
66
+
67
+ Feel free to fork the repository and add back as many features as you want :)
65
68
 
66
69
  ## Configuration
67
70
 
@@ -122,8 +125,10 @@ windows:
122
125
  layout: main-vertical
123
126
  panes:
124
127
  - vim
128
+ - commands:
129
+ - git pull
130
+ - git status
125
131
  - rails server
126
- - git status
127
132
  ```
128
133
 
129
134
  ```
data/lib/teamocil.rb CHANGED
@@ -27,6 +27,7 @@ require 'teamocil/command/split_window'
27
27
  require 'teamocil/tmux/session'
28
28
  require 'teamocil/tmux/window'
29
29
  require 'teamocil/tmux/pane'
30
+ require 'teamocil/tmux/options'
30
31
 
31
32
  module Teamocil
32
33
  class << self
@@ -47,6 +48,10 @@ module Teamocil
47
48
  Kernel.system(*args)
48
49
  end
49
50
 
51
+ def self.query_system(command)
52
+ `#{command}`
53
+ end
54
+
50
55
  def self.parse_options!(arguments: nil)
51
56
  parser = OptionParser.new(arguments: arguments)
52
57
  @options = parser.parsed_options
data/lib/teamocil/cli.rb CHANGED
@@ -6,10 +6,10 @@ module Teamocil
6
6
  Teamocil.parse_options!(arguments: arguments)
7
7
 
8
8
  # List available layouts
9
- return Layout.print_available_layouts(directory: root) if Teamocil.options[:list]
9
+ return Teamocil::Layout.print_available_layouts(directory: root) if Teamocil.options[:list]
10
10
 
11
11
  # Fetch the Layout object
12
- layout = Layout.new(path: layout_file_path)
12
+ layout = Teamocil::Layout.new(path: layout_file_path)
13
13
 
14
14
  # Open layout file in $EDITOR
15
15
  return layout.edit! if Teamocil.options[:edit]
@@ -46,7 +46,7 @@ module Teamocil
46
46
  end
47
47
 
48
48
  if valid?
49
- Session.new(yaml_content)
49
+ Teamocil::Tmux::Session.new(yaml_content)
50
50
  else
51
51
  Teamocil.bail("The layout at `#{path}` is not valid.")
52
52
  end
@@ -0,0 +1,15 @@
1
+ module Teamocil
2
+ module Tmux
3
+ class Options
4
+ def self.fetch_option(option, default: nil)
5
+ value = Teamocil.query_system("tmux show-options -gv #{option}").chomp
6
+ value.empty? ? default : value.to_i
7
+ end
8
+
9
+ def self.fetch_window_option(option, default: nil)
10
+ value = Teamocil.query_system("tmux show-window-options -gv #{option}").chomp
11
+ value.empty? ? default : value.to_i
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,15 +1,13 @@
1
1
  module Teamocil
2
- class Pane < ClosedStruct.new(:index, :root, :commands, :focus)
3
- def as_tmux
4
- [].tap do |tmux|
5
- tmux << Command::SplitWindow.new(root: root) unless first?
6
- tmux << Command::SendKeysToPane.new(index: index, keys: commands.join('; '))
7
- tmux << Command::SendKeysToPane.new(index: index, keys: 'Enter')
2
+ module Tmux
3
+ class Pane < ClosedStruct.new(:index, :root, :commands, :focus, :first)
4
+ def as_tmux
5
+ [].tap do |tmux|
6
+ tmux << Teamocil::Command::SplitWindow.new(root: root) unless first
7
+ tmux << Teamocil::Command::SendKeysToPane.new(index: index, keys: commands.join('; '))
8
+ tmux << Teamocil::Command::SendKeysToPane.new(index: index, keys: 'Enter')
9
+ end
8
10
  end
9
11
  end
10
-
11
- def first?
12
- index == 1
13
- end
14
12
  end
15
13
  end
@@ -1,27 +1,34 @@
1
1
  module Teamocil
2
- class Session < ClosedStruct.new(:name, :windows)
3
- def initialize(object)
4
- super
2
+ module Tmux
3
+ class Session < ClosedStruct.new(:name, :windows)
4
+ def initialize(object)
5
+ super
5
6
 
6
- # Sessions need a name
7
- self.name = "teamocil-session-#{rand(1_000_000)}" unless name
7
+ # Sessions need a name
8
+ self.name = "teamocil-session-#{rand(1_000_000)}" unless name
8
9
 
9
- self.windows = windows.each_with_index.map do |window, index|
10
- # Windows need to know their position
11
- window.merge! index: index + 1
10
+ self.windows = windows.each_with_index.map do |window, index|
11
+ # Windows need to know their position
12
+ window.merge! index: index + window_base_index
13
+ window.merge! first: index.zero?
12
14
 
13
- Window.new(window)
15
+ Teamocil::Tmux::Window.new(window)
16
+ end
14
17
  end
15
- end
16
18
 
17
- def as_tmux
18
- [].tap do |tmux|
19
- tmux << Command::RenameSession.new(name: name)
20
- tmux << windows.map(&:as_tmux)
19
+ def as_tmux
20
+ [].tap do |tmux|
21
+ tmux << Teamocil::Command::RenameSession.new(name: name)
22
+ tmux << windows.map(&:as_tmux)
23
+
24
+ # Set the focus on the right window or do nothing
25
+ focused_window = windows.find(&:focus)
26
+ tmux << Teamocil::Command::SelectWindow.new(index: focused_window.index) if focused_window
27
+ end
28
+ end
21
29
 
22
- # Set the focus on the right window or do nothing
23
- focused_window = windows.find(&:focus)
24
- tmux << Command::SelectWindow.new(index: focused_window.index) if focused_window
30
+ def window_base_index
31
+ @window_base_index ||= Teamocil::Tmux::Options.fetch_option('base-index', default: 0)
25
32
  end
26
33
  end
27
34
  end
@@ -1,46 +1,49 @@
1
1
  module Teamocil
2
- class Window < ClosedStruct.new(:index, :root, :focus, :layout, :name, :panes)
3
- def initialize(object)
4
- super
2
+ module Tmux
3
+ class Window < ClosedStruct.new(:index, :root, :focus, :layout, :name, :panes, :first)
4
+ def initialize(object)
5
+ super
5
6
 
6
- self.panes ||= splits
7
- self.panes = panes.each_with_index.map do |pane, index|
8
- # Support single command instead of `commands` key in Hash
9
- pane = { commands: [pane] } if pane.is_a?(String)
7
+ self.panes ||= splits
8
+ self.panes = panes.each_with_index.map do |pane, index|
9
+ # Support single command instead of `commands` key in Hash
10
+ pane = { commands: [pane] } if pane.is_a?(String)
10
11
 
11
- # Panes need to know their position
12
- pane.merge! index: index + 1
12
+ # Panes need to know their position
13
+ pane.merge! index: index + pane_base_index
14
+ pane.merge! first: index.zero?
13
15
 
14
- # Panes need know the window root directory
15
- pane.merge! root: root
16
+ # Panes need know the window root directory
17
+ pane.merge! root: root
16
18
 
17
- Pane.new(pane)
19
+ Teamocil::Tmux::Pane.new(pane)
20
+ end
18
21
  end
19
- end
20
-
21
- def first?
22
- index == 1
23
- end
24
22
 
25
- def as_tmux
26
- [].tap do |tmux|
27
- # Rename the current window or create a new one
28
- if Teamocil.options[:here] && first?
29
- tmux << Command::RenameWindow.new(name: name)
30
- else
31
- tmux << Command::NewWindow.new(name: name, root: root)
23
+ def as_tmux
24
+ [].tap do |tmux|
25
+ # Rename the current window or create a new one
26
+ if Teamocil.options[:here] && first
27
+ tmux << Teamocil::Command::RenameWindow.new(name: name)
28
+ else
29
+ tmux << Teamocil::Command::NewWindow.new(name: name, root: root)
30
+ end
31
+
32
+ # Execute all panes commands
33
+ tmux << panes.map(&:as_tmux)
34
+
35
+ # Select the window layout
36
+ tmux << Teamocil::Command::SelectLayout.new(layout: layout)
37
+
38
+ # Set the focus on the right pane or the first one
39
+ focused_pane = panes.find(&:focus)
40
+ focused_index = focused_pane ? focused_pane.index : pane_base_index
41
+ tmux << Teamocil::Command::SelectPane.new(index: focused_index)
32
42
  end
43
+ end
33
44
 
34
- # Execute all panes commands
35
- tmux << panes.map(&:as_tmux)
36
-
37
- # Select the window layout
38
- tmux << Command::SelectLayout.new(layout: layout)
39
-
40
- # Set the focus on the right pane or the first one
41
- focused_pane = panes.find(&:focus)
42
- focused_index = focused_pane ? focused_pane.index : 0
43
- tmux << Command::SelectPane.new(index: focused_index)
45
+ def pane_base_index
46
+ @pane_base_index ||= Teamocil::Tmux::Options.fetch_window_option('pane-base-index', default: 0)
44
47
  end
45
48
  end
46
49
  end
@@ -1,3 +1,3 @@
1
1
  module Teamocil
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teamocil
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2014-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,7 @@ files:
80
80
  - lib/teamocil/command/send_keys_to_pane.rb
81
81
  - lib/teamocil/command/split_window.rb
82
82
  - lib/teamocil/layout.rb
83
+ - lib/teamocil/tmux/options.rb
83
84
  - lib/teamocil/tmux/pane.rb
84
85
  - lib/teamocil/tmux/session.rb
85
86
  - lib/teamocil/tmux/window.rb