Class: VagrantPlugins::Tmuxme::Cap::EnsureTmux

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-tmuxme/cap/ensure_tmux.rb

Class Method Summary collapse

Class Method Details

.ensure_tmux(machine, env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/vagrant-tmuxme/cap/ensure_tmux.rb', line 6

def self.ensure_tmux(machine, env)
  return unless machine.communicate.ready?
 
  if tmux_installed?(machine)
    env.ui.info I18n.t('vagrant_tmuxme.tmux_installed')
  else
    env.ui.info I18n.t('vagrant_tmuxme.installing_tmux')
    install_tmux!(machine)
  end
end

.install_tmux!(machine) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-tmuxme/cap/ensure_tmux.rb', line 21

def self.install_tmux!(machine)
  machine.communicate.tap do |comm|
    case machine.guest.name
    when :debian, :ubuntu
      comm.sudo "apt-get update"
      comm.sudo "apt-get install tmux"
    when :fedora, :centos, :redhat
      comm.sudo "yum install tmux"
    when :suse
      comm.sudo "yast2 -i tmux"
    when :gentoo
      comm.sudo "emerge tmux"
    when :arch
      comm.sudo "pacman -s tmux"
    else
      raise Errors::TmuxNotAvailableError, guest: machine.guest.name
    end
  end
end

.tmux_installed?(machine) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vagrant-tmuxme/cap/ensure_tmux.rb', line 17

def self.tmux_installed?(machine)
  machine.communicate.execute("tmux -V") rescue false
end