Class: Automux::Core::Tmux::Session
- Extended by:
- Forwardable
- Includes:
- Support::HooksHelper, Support::OptionsHelper
- Defined in:
- lib/automux/core/tmux/session.rb
Defined Under Namespace
Classes: Data
Instance Attribute Summary collapse
-
#base_index ⇒ Object
readonly
Returns the value of attribute base_index.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #attach_session ⇒ Object
-
#get_binding ⇒ Object
:stopdoc:.
-
#initialize(blueprint_data) ⇒ Session
constructor
A new instance of Session.
-
#link_window(source_session_name, source_window_identifier, index = nil) ⇒ Object
Links window from source session to current session.
-
#move_first_window_or_create_new(window) ⇒ Object
The first window is created alongwith new-session and thus needs to be moved to its correct index.
- #move_window(index) ⇒ Object
- #new_session ⇒ Object
- #new_window(window) ⇒ Object
- #next_available_window_index ⇒ Object
- #rename_window(window, window_name = window.name) ⇒ Object
- #select_layout(window) ⇒ Object
- #select_window(identifier) ⇒ Object
- #send_keys(identifier, command) ⇒ Object
- #set_option(option) ⇒ Object
- #setup ⇒ Object
- #split_window ⇒ Object
- #start_server ⇒ Object
- #window_indexes ⇒ Object
Methods included from Support::HooksHelper
Methods included from Support::CustomAccessors
Constructor Details
#initialize(blueprint_data) ⇒ Session
Returns a new instance of Session.
13 14 15 16 17 18 19 |
# File 'lib/automux/core/tmux/session.rb', line 13 def initialize(blueprint_data) @windows = [] @hooks = [] = [] @base_index = 0 @data = Data.new(blueprint_data) end |
Instance Attribute Details
#base_index ⇒ Object (readonly)
Returns the value of attribute base_index.
9 10 11 |
# File 'lib/automux/core/tmux/session.rb', line 9 def base_index @base_index end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/automux/core/tmux/session.rb', line 9 def data @data end |
Instance Method Details
#attach_session ⇒ Object
85 86 87 |
# File 'lib/automux/core/tmux/session.rb', line 85 def attach_session %[#{ tmux_with_flags } attach-session -t #{ name }] end |
#get_binding ⇒ Object
:stopdoc:
103 104 105 |
# File 'lib/automux/core/tmux/session.rb', line 103 def get_binding binding end |
#link_window(source_session_name, source_window_identifier, index = nil) ⇒ Object
Links window from source session to current session. Window name or index must be provided.
E.g.: link_window(primary, finch, 3)
-
links a window named finch from an existing session named primary as 3rd window in current session.
81 82 83 |
# File 'lib/automux/core/tmux/session.rb', line 81 def link_window(source_session_name, source_window_identifier, index = nil) %[tmux link-window -s #{ source_session_name }:#{ source_window_identifier } -t #{ name }:#{ index }] end |
#move_first_window_or_create_new(window) ⇒ Object
The first window is created alongwith new-session and thus needs to be moved to its correct index.
51 52 53 54 55 56 57 |
# File 'lib/automux/core/tmux/session.rb', line 51 def move_first_window_or_create_new(window) if window == windows.first move_window(window.index) else new_window(window) end end |
#move_window(index) ⇒ Object
63 64 65 |
# File 'lib/automux/core/tmux/session.rb', line 63 def move_window(index) %[tmux move-window -t #{ name }:#{ index }] end |
#new_session ⇒ Object
38 39 40 |
# File 'lib/automux/core/tmux/session.rb', line 38 def new_session %[#{ tmux_with_flags } new-session -d -s #{ name }] end |
#new_window(window) ⇒ Object
46 47 48 |
# File 'lib/automux/core/tmux/session.rb', line 46 def new_window(window) %[tmux new-window -t #{ name }:#{ window.index }] end |
#next_available_window_index ⇒ Object
114 115 116 117 |
# File 'lib/automux/core/tmux/session.rb', line 114 def next_available_window_index n = base_index + number_of_windows (Array(base_index..n) - window_indexes).first end |
#rename_window(window, window_name = window.name) ⇒ Object
59 60 61 |
# File 'lib/automux/core/tmux/session.rb', line 59 def rename_window(window, window_name = window.name) %[tmux rename-window -t #{ name }:#{ window.index } #{ window_name }] end |
#select_layout(window) ⇒ Object
89 90 91 |
# File 'lib/automux/core/tmux/session.rb', line 89 def select_layout(window) %[tmux select-layout -t #{ name }:#{ window.index } #{ window.layout }] end |
#select_window(identifier) ⇒ Object
72 73 74 75 |
# File 'lib/automux/core/tmux/session.rb', line 72 def select_window(identifier) window = get_window(identifier) %[tmux select-window -t #{ name }:#{ window.index }] end |
#send_keys(identifier, command) ⇒ Object
67 68 69 70 |
# File 'lib/automux/core/tmux/session.rb', line 67 def send_keys(identifier, command) window = get_window(identifier) %[tmux send-keys -t #{ name }:#{ window.index } "#{ command }" C-m] end |
#set_option(option) ⇒ Object
42 43 44 |
# File 'lib/automux/core/tmux/session.rb', line 42 def set_option(option) %[tmux set-option #{ option.name } '#{ option.value }'] end |
#setup ⇒ Object
107 108 109 110 111 112 |
# File 'lib/automux/core/tmux/session.rb', line 107 def setup setup_base_index setup_windows setup_hooks end |
#split_window ⇒ Object
93 94 95 |
# File 'lib/automux/core/tmux/session.rb', line 93 def split_window %[tmux split-window] end |
#start_server ⇒ Object
34 35 36 |
# File 'lib/automux/core/tmux/session.rb', line 34 def start_server %[tmux start-server] end |
#window_indexes ⇒ Object
97 98 99 |
# File 'lib/automux/core/tmux/session.rb', line 97 def window_indexes @windows.map(&:index).compact end |