Class: Pair::Session::Tmux

Inherits:
Object
  • Object
show all
Defined in:
lib/pair/session/tmux.rb

Constant Summary collapse

TMP_PATH =
"/tmp"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Tmux

Returns a new instance of Tmux.



11
12
13
14
# File 'lib/pair/session/tmux.rb', line 11

def initialize(session)
  self.session = session
  create_socket_directory
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



8
9
10
# File 'lib/pair/session/tmux.rb', line 8

def session
  @session
end

Instance Method Details

#app_pathObject



16
17
18
# File 'lib/pair/session/tmux.rb', line 16

def app_path
  self.class.to_s.split('::').first.downcase
end

#attach(read_only = false) ⇒ Object



49
50
51
52
53
54
# File 'lib/pair/session/tmux.rb', line 49

def attach(read_only = false)
  args = %W[-S #{socket_path} attach]
  args += " -r" if read_only

  system "tmux", *args
end

#startObject



24
25
26
27
28
29
# File 'lib/pair/session/tmux.rb', line 24

def start
  args = %W[-S #{socket_path} new-session -d]
  system "tmux", *args

  at_exit { stop }
end

#stopObject



31
32
33
34
35
# File 'lib/pair/session/tmux.rb', line 31

def stop
  `lsof -t #{socket_path}/ | xargs kill -9`
  FileUtils.rm_f(socket_path)
  self.session.cleanup_authorized_keys if self.session.respond_to?(:cleanup_authorized_keys)
end

#uniqueObject



20
21
22
# File 'lib/pair/session/tmux.rb', line 20

def unique
  @unique ||= srand.to_s[0,5]
end

#window(command) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pair/session/tmux.rb', line 37

def window(command)
  args = %W[
    -S #{socket_path}
    new-window
    -t #{session.name}:0
    -n 'Pairing'
    'ssh [email protected] -A'
  ]

  system "tmux", *args
end