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

Class Method Details

.attach_session(name, tmux: "tmux") ⇒ Array<String>

Attach to a session

Parameters:

  • name (String)

    Session name

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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)

Parameters:

  • format (String)

    Format string (e.g., “#S” for session name)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


177
178
179
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 177

def display_message(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)

Parameters:

  • target (String)

    Target window/pane (e.g., “session:window.0”)

  • format (String)

    Format string (e.g., “#window_widthx#window_height”)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


186
187
188
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 186

def display_message_target(target, format, tmux: "tmux")
  [tmux, "display-message", "-t", target, "-p", format]
end

.has_session(name, tmux: "tmux") ⇒ Array<String>

Check if a session exists

Parameters:

  • name (String)

    Session name

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • name (String)

    Session name

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target window (e.g., “session:window”)

  • format (String, nil) (defaults to: nil)

    Format string (e.g., “#pane_index”)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • format (String, nil) (defaults to: nil)

    Format string

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • name (String)

    Session name

  • root (String, nil) (defaults to: nil)

    Working directory

  • window_name (String, nil) (defaults to: nil)

    Name for the first window

  • tmux_options (String, nil) (defaults to: nil)

    Additional tmux options

  • print_format (String, nil) (defaults to: nil)

    Format string for -P -F (captures window info)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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(tmux_options.split) if tmux_options
  cmd.concat(["new-session", "-d", "-s", name])
  cmd.concat(["-n", window_name]) if window_name
  cmd.concat(["-c", File.expand_path(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

Parameters:

  • session (String)

    Session name

  • name (String, nil) (defaults to: nil)

    Window name

  • root (String, nil) (defaults to: nil)

    Working directory

  • print_format (String, nil) (defaults to: nil)

    Format string for -P -F (captures window info)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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.expand_path(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

Parameters:

  • target (String)

    Target window

  • layout (String)

    Layout name (e.g., “main-vertical”, “tiled”)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target pane (e.g., “session:window.pane”)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target window (e.g., “session:window”)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target pane (e.g., “session:window.pane”)

  • keys (String)

    Keys/command to send

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • session (String)

    Session name

  • name (String)

    Environment variable name

  • value (String, nil) (defaults to: nil)

    Value to set (ignored when unset: true)

  • unset (Boolean) (defaults to: false)

    Unset the variable instead of setting it

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target pane

  • option (String)

    Option name

  • value (String, Integer)

    Option value

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target window

  • option (String)

    Option name (e.g., “main-pane-width”)

  • value (String, Integer)

    Option value

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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

Parameters:

  • target (String)

    Target window (e.g., “session:window”)

  • root (String, nil) (defaults to: nil)

    Working directory

  • horizontal (Boolean) (defaults to: false)

    Split horizontally (default: vertically)

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


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.expand_path(root)]) if root
  cmd
end

.version(tmux: "tmux") ⇒ Array<String>

Parameters:

  • tmux (String) (defaults to: "tmux")

    tmux binary path

Returns:

  • (Array<String>)


15
16
17
# File 'lib/ace/tmux/atoms/tmux_command_builder.rb', line 15

def version(tmux: "tmux")
  [tmux, "-V"]
end