Class: Ace::Tmux::Molecules::TmuxExecutor
- Inherits:
-
Object
- Object
- Ace::Tmux::Molecules::TmuxExecutor
- 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
-
#capture(cmd) ⇒ ExecutionResult
Run a command and capture output.
-
#exec(cmd) ⇒ void
Replace current process with command (for tmux attach).
-
#run(cmd) ⇒ Boolean
Run a command via system (fire and forget with status).
-
#tmux_available?(tmux: "tmux") ⇒ Boolean
Check if tmux is available.
Instance Method Details
#capture(cmd) ⇒ ExecutionResult
Run a command and capture output
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)
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)
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
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 |