class Teamocil::Tmux::Window
Public Class Methods
new(object)
click to toggle source
Calls superclass method
# File lib/teamocil/tmux/window.rb, line 4 def initialize(object) super # Make sure paths like `~/foo/bar` work self.root = File.expand_path(root) if root self.panes ||= [] self.panes = panes.each_with_index.map do |pane, index| # Support single command instead of `commands` key in Hash pane = { commands: [pane] } if pane.is_a?(String) # Panes need to know their position pane.merge! index: index # Panes need to know the window root directory pane.merge! root: root # Panes need to know the window layout pane.merge! layout: layout # Panes need to know the window name pane.merge! name: name Teamocil::Tmux::Pane.new(pane) end end
window_base_index()
click to toggle source
# File lib/teamocil/tmux/window.rb, line 67 def self.window_base_index @window_base_index ||= begin base_index = Teamocil::Tmux.option('base-index', default: 0) current_window_count = Teamocil::Tmux.window_count # If `--here` is specified, treat the current window as a new one current_window_count -= 1 if Teamocil.options[:here] base_index + current_window_count end end
Public Instance Methods
as_tmux()
click to toggle source
# File lib/teamocil/tmux/window.rb, line 31 def as_tmux [].tap do |tmux| # Rename the current window or create a new one if Teamocil.options[:here] && first? if root first_pane_index = panes.first.internal_index tmux << Teamocil::Command::SendKeysToPane.new(index: first_pane_index, keys: %Q(cd "#{root}")) tmux << Teamocil::Command::SendKeysToPane.new(index: first_pane_index, keys: 'Enter') end tmux << Teamocil::Command::RenameWindow.new(name: name) else tmux << Teamocil::Command::NewWindow.new(name: name, root: root) end # Set window options if options tmux << options.map do |(option, value)| Teamocil::Command::SetWindowOption.new(name: name, option: option, value: value) end end # Execute all panes commands tmux << panes.map(&:as_tmux).flatten # Set the focus on the right pane or the first one focused_pane = panes.find(&:focus) focused_index = focused_pane ? focused_pane.internal_index : "#{name}.#{Teamocil::Tmux::Pane.pane_base_index}" tmux << Teamocil::Command::SelectPane.new(index: focused_index) end.flatten end
internal_index()
click to toggle source
# File lib/teamocil/tmux/window.rb, line 63 def internal_index index + self.class.window_base_index end
Protected Instance Methods
first?()
click to toggle source
# File lib/teamocil/tmux/window.rb, line 81 def first? index.zero? end