Class: Ace::Tmux::Molecules::TmuxExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/tmux/molecules/tmux_executor.rb

Overview

Executes tmux commands via different execution strategies

Provides three modes:

- capture: Run and capture stdout/stderr (for queries)
- run: Run via system() (for mutations)
- exec: Replace process via Kernel.exec (for attach)

Instance Method Summary collapse

Instance Method Details

#capture(cmd) ⇒ ExecutionResult

Run a command and capture output

Parameters:

  • cmd (Array<String>)

    Command array

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/ace/tmux/molecules/tmux_executor.rb', line 19

def capture(cmd)
  stdout, stderr, status = Open3.capture3(*with_socket_target(cmd))
  ExecutionResult.new(
    stdout: stdout.strip,
    stderr: stderr.strip,
    success: status.success?,
    exit_code: status.exitstatus
  )
end

#exec(cmd) ⇒ void

This method returns an undefined value.

Replace current process with command (for tmux attach)

Parameters:

  • cmd (Array<String>)

    Command array



41
42
43
# File 'lib/ace/tmux/molecules/tmux_executor.rb', line 41

def exec(cmd)
  Kernel.exec(*with_socket_target(cmd))
end

#run(cmd) ⇒ Boolean

Run a command via system (fire and forget with status)

Parameters:

  • cmd (Array<String>)

    Command array

Returns:

  • (Boolean)

    true if command succeeded



33
34
35
# File 'lib/ace/tmux/molecules/tmux_executor.rb', line 33

def run(cmd)
  system(*with_socket_target(cmd))
end

#tmux_available?(tmux: "tmux") ⇒ Boolean

Check if tmux is available

Parameters:

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

    tmux binary path

Returns:

  • (Boolean)


49
50
51
52
53
54
# File 'lib/ace/tmux/molecules/tmux_executor.rb', line 49

def tmux_available?(tmux: "tmux")
  result = capture([tmux, "-V"])
  result.success?
rescue Errno::ENOENT
  false
end