Module: Ace::Tmux::Atoms::TmuxCommandBuilder
- Defined in:
- lib/ace/tmux/atoms/tmux_command_builder.rb
Overview
Pure functions for building tmux CLI command arrays
Each method returns an Array<String> suitable for Open3.capture3 or system(). No I/O — just data transformation.
Class Method Summary collapse
-
.attach_session(name, tmux: "tmux") ⇒ Array<String>
Attach to a session.
- .capture_pane(target, lines: 40, tmux: "tmux") ⇒ Object
- .capture_pane_visible(target, start_line:, end_line:, include_alternate: false, tmux: "tmux") ⇒ Object
- .detach_client(session, tmux: "tmux") ⇒ Object
-
.display_message(format, tmux: "tmux") ⇒ Array<String>
Display a message (useful for getting current session name).
-
.display_message_target(target, format, tmux: "tmux") ⇒ Array<String>
Display a message for a specific target (useful for getting window dimensions).
-
.has_session(name, tmux: "tmux") ⇒ Array<String>
Check if a session exists.
-
.kill_session(name, tmux: "tmux") ⇒ Array<String>
Kill a session.
-
.list_panes(target, format: nil, tmux: "tmux") ⇒ Array<String>
List panes in a window.
-
.list_sessions(format: nil, tmux: "tmux") ⇒ Array<String>
List sessions.
- .list_windows(target, format: nil, tmux: "tmux") ⇒ Object
-
.new_session(name, root: nil, window_name: nil, tmux_options: nil, print_format: nil, tmux: "tmux") ⇒ Array<String>
Create a new detached session.
-
.new_window(session, name: nil, root: nil, print_format: nil, tmux: "tmux") ⇒ Array<String>
Create a new window in an existing session.
-
.select_layout(target, layout, tmux: "tmux") ⇒ Array<String>
Set the layout for a window.
-
.select_pane(target, tmux: "tmux") ⇒ Array<String>
Select (focus) a specific pane.
-
.select_window(target, tmux: "tmux") ⇒ Array<String>
Select (focus) a specific window.
-
.send_keys(target, keys, tmux: "tmux") ⇒ Array<String>
Send keys (commands) to a target pane.
- .send_raw_keys(target, *keys, tmux: "tmux") ⇒ Object
-
.set_environment(session, name, value: nil, unset: false, tmux: "tmux") ⇒ Array<String>
Set or unset a session environment variable.
-
.set_pane_option(target, option, value, tmux: "tmux") ⇒ Array<String>
Set a pane option.
-
.set_window_option(target, option, value, tmux: "tmux") ⇒ Array<String>
Set a window option.
-
.split_window(target, root: nil, horizontal: false, print_format: nil, tmux: "tmux") ⇒ Array<String>
Split a window to create a new pane.
- .version(tmux: "tmux") ⇒ Array<String>
Class Method Details
.attach_session(name, tmux: "tmux") ⇒ Array<String>
Attach to a session
117 118 119 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 117 def attach_session(name, tmux: "tmux") [tmux, "attach-session", "-t", name] end |
.capture_pane(target, lines: 40, tmux: "tmux") ⇒ Object
212 213 214 215 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 212 def capture_pane(target, lines: 40, tmux: "tmux") start = -Integer(lines.to_i.abs) [tmux, "capture-pane", "-p", "-t", target, "-S", start.to_s, "-E", "-1"] end |
.capture_pane_visible(target, start_line:, end_line:, include_alternate: false, tmux: "tmux") ⇒ Object
217 218 219 220 221 222 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 217 def capture_pane_visible(target, start_line:, end_line:, include_alternate: false, tmux: "tmux") cmd = [tmux, "capture-pane", "-p"] cmd << "-a" if include_alternate cmd.concat(["-t", target, "-S", Integer(start_line).to_s, "-E", Integer(end_line).to_s]) cmd end |
.detach_client(session, tmux: "tmux") ⇒ Object
224 225 226 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 224 def detach_client(session, tmux: "tmux") [tmux, "detach-client", "-s", session] end |
.display_message(format, tmux: "tmux") ⇒ Array<String>
Display a message (useful for getting current session name)
188 189 190 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 188 def (format, tmux: "tmux") [tmux, "display-message", "-p", format] end |
.display_message_target(target, format, tmux: "tmux") ⇒ Array<String>
Display a message for a specific target (useful for getting window dimensions)
197 198 199 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 197 def (target, format, tmux: "tmux") [tmux, "display-message", "-t", target, "-p", format] end |
.has_session(name, tmux: "tmux") ⇒ Array<String>
Check if a session exists
23 24 25 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 23 def has_session(name, tmux: "tmux") [tmux, "has-session", "-t", name] end |
.kill_session(name, tmux: "tmux") ⇒ Array<String>
Kill a session
125 126 127 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 125 def kill_session(name, tmux: "tmux") [tmux, "kill-session", "-t", name] end |
.list_panes(target, format: nil, tmux: "tmux") ⇒ Array<String>
List panes in a window
206 207 208 209 210 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 206 def list_panes(target, format: nil, tmux: "tmux") cmd = [tmux, "list-panes", "-t", target] cmd.concat(["-F", format]) if format cmd end |
.list_sessions(format: nil, tmux: "tmux") ⇒ Array<String>
List sessions
133 134 135 136 137 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 133 def list_sessions(format: nil, tmux: "tmux") cmd = [tmux, "list-sessions"] cmd.concat(["-F", format]) if format cmd end |
.list_windows(target, format: nil, tmux: "tmux") ⇒ Object
139 140 141 142 143 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 139 def list_windows(target, format: nil, tmux: "tmux") cmd = [tmux, "list-windows", "-t", target] cmd.concat(["-F", format]) if format cmd end |
.new_session(name, root: nil, window_name: nil, tmux_options: nil, print_format: nil, tmux: "tmux") ⇒ Array<String>
Create a new detached session
35 36 37 38 39 40 41 42 43 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 35 def new_session(name, root: nil, window_name: nil, tmux_options: nil, print_format: nil, tmux: "tmux") cmd = [tmux] cmd.concat(.split) if cmd.concat(["new-session", "-d", "-s", name]) cmd.concat(["-n", window_name]) if window_name cmd.concat(["-c", File.(root)]) if root cmd.concat(["-P", "-F", print_format]) if print_format cmd end |
.new_window(session, name: nil, root: nil, print_format: nil, tmux: "tmux") ⇒ Array<String>
Create a new window in an existing session
52 53 54 55 56 57 58 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 52 def new_window(session, name: nil, root: nil, print_format: nil, tmux: "tmux") cmd = [tmux, "new-window", "-t", "#{session}:"] cmd.concat(["-n", name]) if name cmd.concat(["-c", File.(root)]) if root cmd.concat(["-P", "-F", print_format]) if print_format cmd end |
.select_layout(target, layout, tmux: "tmux") ⇒ Array<String>
Set the layout for a window
93 94 95 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 93 def select_layout(target, layout, tmux: "tmux") [tmux, "select-layout", "-t", target, layout] end |
.select_pane(target, tmux: "tmux") ⇒ Array<String>
Select (focus) a specific pane
109 110 111 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 109 def select_pane(target, tmux: "tmux") [tmux, "select-pane", "-t", target] end |
.select_window(target, tmux: "tmux") ⇒ Array<String>
Select (focus) a specific window
101 102 103 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 101 def select_window(target, tmux: "tmux") [tmux, "select-window", "-t", target] end |
.send_keys(target, keys, tmux: "tmux") ⇒ Array<String>
Send keys (commands) to a target pane
80 81 82 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 80 def send_keys(target, keys, tmux: "tmux") [tmux, "send-keys", "-t", target, keys, "Enter"] end |
.send_raw_keys(target, *keys, tmux: "tmux") ⇒ Object
84 85 86 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 84 def send_raw_keys(target, *keys, tmux: "tmux") [tmux, "send-keys", "-t", target, *keys] end |
.set_environment(session, name, value: nil, unset: false, tmux: "tmux") ⇒ Array<String>
Set or unset a session environment variable
172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 172 def set_environment(session, name, value: nil, unset: false, tmux: "tmux") cmd = [tmux, "set-environment", "-t", session] if unset cmd.concat(["-u", name]) elsif value cmd.concat([name, value]) else cmd << name end cmd end |
.set_pane_option(target, option, value, tmux: "tmux") ⇒ Array<String>
Set a pane option
161 162 163 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 161 def set_pane_option(target, option, value, tmux: "tmux") [tmux, "set-option", "-p", "-t", target, option, value.to_s] end |
.set_window_option(target, option, value, tmux: "tmux") ⇒ Array<String>
Set a window option
151 152 153 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 151 def set_window_option(target, option, value, tmux: "tmux") [tmux, "set-window-option", "-t", target, option, value.to_s] end |
.split_window(target, root: nil, horizontal: false, print_format: nil, tmux: "tmux") ⇒ Array<String>
Split a window to create a new pane
66 67 68 69 70 71 72 73 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 66 def split_window(target, root: nil, horizontal: false, print_format: nil, tmux: "tmux") cmd = [tmux, "split-window"] cmd << "-h" if horizontal cmd.concat(["-t", target]) cmd.concat(["-c", File.(root)]) if root cmd.concat(["-P", "-F", print_format]) if print_format cmd end |
.version(tmux: "tmux") ⇒ Array<String>
15 16 17 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 15 def version(tmux: "tmux") [tmux, "-V"] end |