class Tmuxinator::Cli

Attributes

command_list[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method
# File lib/tmuxinator/cli.rb, line 7
def initialize(*args)
  super
  @command_list = %w(commands copy debug delete doctor help implode list start version)
end

Public Instance Methods

commands() click to toggle source
# File lib/tmuxinator/cli.rb, line 16
def commands
  puts command_list.join("\n")
end
completions(arg) click to toggle source
# File lib/tmuxinator/cli.rb, line 22
def completions(arg)
  if %w(start open copy delete).include?(arg)
    configs = Tmuxinator::Config.configs
    puts configs
  end
end
copy(existing, new) click to toggle source
# File lib/tmuxinator/cli.rb, line 73
def copy(existing, new)
  existing_config_path = Tmuxinator::Config.project(existing)
  new_config_path = Tmuxinator::Config.project(new)

  exit!("Project #{existing} doesn't exist!") unless Tmuxinator::Config.exists?(existing)

  if Tmuxinator::Config.exists?(new)
    if yes?("#{new} already exists, would you like to overwrite it?", :red)
      FileUtils.rm(new_config_path)
      say "Overwriting #{new}"
    end
  end

  FileUtils.copy_file(existing_config_path, new_config_path)
  Kernel.system("$EDITOR #{new_config_path}")
end
debug(name) click to toggle source
# File lib/tmuxinator/cli.rb, line 64
def debug(name)
  project = Tmuxinator::Config.validate(name)
  puts project.render
end
delete(project) click to toggle source
# File lib/tmuxinator/cli.rb, line 94
def delete(project)
  if Tmuxinator::Config.exists?(project)
    config =  "#{Tmuxinator::Config.root}/#{project}.yml"

    if yes?("Are you sure you want to delete #{project}?(y/n)", :red)
      FileUtils.rm(config)
      say "Deleted #{project}"
    end
  else
    exit! "That file doesn't exist."
  end
end
doctor() click to toggle source
# File lib/tmuxinator/cli.rb, line 136
def doctor
  say "Checking if tmux is installed ==> "
  yes_no Tmuxinator::Config.installed?

  say "Checking if $EDITOR is set ==> "
  yes_no Tmuxinator::Config.editor?

  say "Checking if $SHELL is set ==> "
  yes_no  Tmuxinator::Config.shell?
end
implode() click to toggle source
# File lib/tmuxinator/cli.rb, line 110
def implode
  if yes?("Are you sure you want to delete all tmuxinator configs?", :red)
    FileUtils.remove_dir(Tmuxinator::Config.root)
    say "Deleted all tmuxinator projects."
  end
end
list() click to toggle source
# File lib/tmuxinator/cli.rb, line 121
def list
  say "tmuxinator projects:"

  print_in_columns Tmuxinator::Config.configs
end
new(name) click to toggle source
# File lib/tmuxinator/cli.rb, line 34
def new(name)
  config = Tmuxinator::Config.project(name)

  unless Tmuxinator::Config.exists?(name)
    template = Tmuxinator::Config.default? ? Tmuxinator::Config.default : Tmuxinator::Config.sample
    erb  = Erubis::Eruby.new(File.read(template)).result(binding)
    File.open(config, "w") { |f| f.write(erb) }
  end

  Kernel.system("$EDITOR #{config}") || doctor
end
start(name) click to toggle source
# File lib/tmuxinator/cli.rb, line 49
def start(name)
  project = Tmuxinator::Config.validate(name)

  if project.deprecations.any?
    project.deprecations.each { |deprecation| say deprecation, :red }
    puts
    print "Press ENTER to continue."
    STDIN.getc
  end

  Kernel.exec(project.render)
end
version() click to toggle source
# File lib/tmuxinator/cli.rb, line 130
def version
  say "tmuxinator #{Tmuxinator::VERSION}"
end