class Tmuxinator::Cli

Constants

COMMANDS

Public Instance Methods

commands(shell = nil) click to toggle source
# File lib/tmuxinator/cli.rb, line 24
def commands(shell = nil)
  out = if shell == "zsh"
    COMMANDS.map do |command, desc|
      "#{command}:#{desc}"
    end.join("\n")
  else
    COMMANDS.keys.join("\n")
  end

  puts out
end
completions(arg) click to toggle source
# File lib/tmuxinator/cli.rb, line 38
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 91
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) or yes?("#{new} already exists, would you like to overwrite it?", :red)
    say "Overwriting #{new}" if Tmuxinator::Config.exists?(new)
    FileUtils.copy_file(existing_config_path, new_config_path)
  end

  Kernel.system("$EDITOR #{new_config_path}")
end
debug(name, custom_name = nil) click to toggle source
# File lib/tmuxinator/cli.rb, line 82
def debug(name, custom_name  = nil)
  project = Tmuxinator::Config.validate(name, custom_name )
  puts project.render
end
delete(project) click to toggle source
# File lib/tmuxinator/cli.rb, line 109
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 151
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 125
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 136
def list
  say "tmuxinator projects:"

  print_in_columns Tmuxinator::Config.configs
end
new(name) click to toggle source
# File lib/tmuxinator/cli.rb, line 52
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, custom_name = nil) click to toggle source
# File lib/tmuxinator/cli.rb, line 67
def start(name, custom_name  = nil)
  project = Tmuxinator::Config.validate(name, custom_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 145
def version
  say "tmuxinator #{Tmuxinator::VERSION}"
end