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.
-
.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.
-
.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.
-
.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, 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
112 113 114 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 112 def attach_session(name, tmux: "tmux") [tmux, "attach-session", "-t", name] end |
.display_message(format, tmux: "tmux") ⇒ Array<String>
Display a message (useful for getting current session name)
177 178 179 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 177 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)
186 187 188 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 186 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
120 121 122 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 120 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
195 196 197 198 199 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 195 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
128 129 130 131 132 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 128 def list_sessions(format: nil, tmux: "tmux") cmd = [tmux, "list-sessions"] 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
88 89 90 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 88 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
104 105 106 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 104 def select_pane(target, tmux: "tmux") [tmux, "select-pane", "-t", target] end |
.select_window(target, tmux: "tmux") ⇒ Array<String>
Select (focus) a specific window
96 97 98 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 96 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
79 80 81 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 79 def send_keys(target, keys, tmux: "tmux") [tmux, "send-keys", "-t", target, keys, "Enter"] end |
.set_environment(session, name, value: nil, unset: false, tmux: "tmux") ⇒ Array<String>
Set or unset a session environment variable
161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 161 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
150 151 152 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 150 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
140 141 142 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 140 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, tmux: "tmux") ⇒ Array<String>
Split a window to create a new pane
66 67 68 69 70 71 72 |
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 66 def split_window(target, root: nil, horizontal: false, tmux: "tmux") cmd = [tmux, "split-window"] cmd << "-h" if horizontal cmd.concat(["-t", target]) cmd.concat(["-c", File.(root)]) if root 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 |