Class: ScTmux::Sc

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging, Methadone::Main, Methadone::SH
Defined in:
lib/sc_tmux.rb

Class Method Summary collapse

Class Method Details

.attachObject



73
74
75
76
# File 'lib/sc_tmux.rb', line 73

def self.attach
  grab
  sh("tmux -L #{options[:name]} attach")
end

.createObject



68
69
70
71
# File 'lib/sc_tmux.rb', line 68

def self.create
  grab
  sh("tmux -L #{options[:name]}")
end

.fixObject



58
59
60
# File 'lib/sc_tmux.rb', line 58

def self.fix
  puts File.read(options[:agent_file])
end

.grabObject



48
49
50
51
52
53
54
55
56
# File 'lib/sc_tmux.rb', line 48

def self.grab
  File.unlink(options[:agent_file]) if File.exist?(options[:agent_file])
  f = File.new(options[:agent_file], "w")

  %w(SSH_CLIENT SSH_TTY SSH_AUTH_SOCK SSH_CONNECTION).each do |var|
    f.write("#{var}=\"#{ENV[var]}\"\n")
  end
  f.close
end

.setupObject



43
44
45
46
# File 'lib/sc_tmux.rb', line 43

def self.setup
  puts "Add the following alias to wherever you keep aliases:"
  puts "alias fixssh='eval $(sc -f)'"
end

.ssh(host) ⇒ Object



62
63
64
65
66
# File 'lib/sc_tmux.rb', line 62

def self.ssh(host)
  which_ssh = `which ssh`.chomp
  display_host = /(.+@)?(([0-9]+\.){3}[0-9]+|([^.]+))/.match(host)[2]
  sh("tmux new-window -n #{display_host} \"echo 'Using: #{which_ssh}' ; . #{options[:agent_file]} ; ssh -A #{host}\"")
end