Class: Appear::Tmux

Inherits:
Service show all
Defined in:
lib/appear/tmux.rb

Overview

The Tmux service is in charge of interacting with ‘tmux` processes. It is used by the Tmux revealer, but could also be used as the building block for other tmux-related scripts.

see the man page for tmux if you are curious about what clients, windows, panes, and sessions are in Tmux world.

Defined Under Namespace

Classes: Client, Pane, Session, TmuxValue, Window

Instance Method Summary collapse

Methods inherited from BaseService

delegate, require_service, required_services

Constructor Details

#initialize(svcs = {}) ⇒ Tmux

Returns a new instance of Tmux.



220
221
222
223
# File 'lib/appear/tmux.rb', line 220

def initialize(svcs = {})
  super(svcs)
  @memo = ::Appear::Util::Memoizer.new
end

Instance Method Details

#attach_session_command(session) ⇒ Appear::Util::CommandBuilder

Construct a command that will attach the given session when run

Parameters:

  • session (String)

    use Session#target

Returns:



287
288
289
# File 'lib/appear/tmux.rb', line 287

def attach_session_command(session)
  command('attach-session').flags(:t => session)
end

#clientsArray<Client>

List all the tmux clients on the system

Returns:



228
229
230
# File 'lib/appear/tmux.rb', line 228

def clients
  ipc_returning(command('list-clients'), Client)
end

#new_session(opts = {}) ⇒ Object

Create a new session



274
275
276
# File 'lib/appear/tmux.rb', line 274

def new_session(opts = {})
  ipc_returning_one(command('new-session').flags(opts), Session)
end

#new_window(opts = {}) ⇒ Object

Create a new window



264
265
266
# File 'lib/appear/tmux.rb', line 264

def new_window(opts = {})
  ipc_returning_one(command('new-window').flags(opts), Window)
end

#panesArray<Pane>

List all the tmux panes on the system

Returns:



235
236
237
# File 'lib/appear/tmux.rb', line 235

def panes
  ipc_returning(command('list-panes').flags(:a => true), Pane)
end

#reveal_pane(pane) ⇒ Object

Reveal a pane in tmux.

Parameters:

  • pane (Pane)

    a pane



256
257
258
259
260
261
# File 'lib/appear/tmux.rb', line 256

def reveal_pane(pane)
  ipc(command('select-pane').flags(:t => pane.target))
  # TODO: how do we use a real target for this?
  ipc(command('select-window').flags(:t => "#{pane.session}:#{pane.window}"))
  pane
end

#send_keys(pane, keys, opts = {}) ⇒ Object

Send keys to a pane



279
280
281
# File 'lib/appear/tmux.rb', line 279

def send_keys(pane, keys, opts = {})
  ipc(command('send-keys').flags(opts.merge(:t => pane.target)).args(*keys))
end

#sessionsArray<Session>

List all the tmux sessions on the system

Returns:



242
243
244
# File 'lib/appear/tmux.rb', line 242

def sessions
  ipc_returning(command('list-sessions'), Session)
end

#split_window(opts = {}) ⇒ Object

Split a window



269
270
271
# File 'lib/appear/tmux.rb', line 269

def split_window(opts = {})
  ipc_returning_one(command('split-window').flags(opts), Pane)
end

#windowsArray<Window>

List all the tmux windows in any session on the system

Returns:



249
250
251
# File 'lib/appear/tmux.rb', line 249

def windows
  ipc_returning(command('list-windows').flags(:a => true), Window)
end