class Procmux::Prox

Public Class Methods

new(procfile: nil, proclist: nil, session_name: nil) click to toggle source
# File lib/procmux/prox.rb, line 6
def initialize(procfile: nil, proclist: nil, session_name: nil)
  @session = session_name || auto_session_name
  parse_file procfile if procfile
  parse proclist if proclist
  `tmux start-server`
end

Public Instance Methods

attach_to_tmux!() click to toggle source
# File lib/procmux/prox.rb, line 53
def attach_to_tmux!
  exec "tmux attach-session -t #{@session}"
end
auto_session_name() click to toggle source
# File lib/procmux/prox.rb, line 21
def auto_session_name
  "proxmux_#{File.basename(Dir.pwd).gsub(/\s/, '_')}"
end
check_tmux_session_exists() click to toggle source
# File lib/procmux/prox.rb, line 57
def check_tmux_session_exists
  system "tmux has -t #{@session}"
end
parse(proclist) click to toggle source
# File lib/procmux/prox.rb, line 25
def parse(proclist)
  proclist.is_a? String or raise ArgumentError, 'Proclist must be String'

  @procs = proclist.lines
          .lazy
          .map(&:chomp)
          .map { |line| ProcEntry.new(*line.match(PROC_RE)[1..2])}
end
parse_file(filepath) click to toggle source
# File lib/procmux/prox.rb, line 34
def parse_file(filepath)
  parse File.open(filepath).read
end
populate_tmux_session() click to toggle source
# File lib/procmux/prox.rb, line 42
def populate_tmux_session
  @procs.each_with_index do |p, i|
    if i==0
      `tmux rename-window -t 0 '#{p.label}'`
    else
      `tmux new-window -t #{@session}:#{i} -n '#{p.label}'`
    end
    `tmux send-keys -t '#{p.label}' '#{p.command}' C-m`
  end
end
run!() click to toggle source
# File lib/procmux/prox.rb, line 13
def run!
  attach_to_tmux! if check_tmux_session_exists

  start_tmux_session
  populate_tmux_session
  attach_to_tmux!
end
start_tmux_session() click to toggle source
# File lib/procmux/prox.rb, line 38
def start_tmux_session
  system "tmux new-session -d -s #{@session}" or raise "Error starting Tmux session!"
end