def initialize(argv, env)
parse_options! argv
layout_path = env["TEAMOCIL_PATH"] || File.join("#{env["HOME"]}", ".teamocil")
if @options.include?(:list)
@layouts = get_layouts(layout_path)
return print_layouts
end
file = @options[:layout] || ::File.join(layout_path, "#{argv[0]}.yml")
if @options[:edit]
::FileUtils.touch file unless File.exists?(file)
Kernel.system("$EDITOR \"#{file}\"")
elsif @options[:show]
::FileUtils.touch file unless File.exists?(file)
Kernel.system("cat \"#{file}\"")
else
bail "There is no file \"#{file}\"" unless File.exists?(file)
bail "You must be in a tmux session to use teamocil" unless env["TMUX"]
yaml = ERB.new(File.read(file)).result
@layout = Teamocil::Layout.new(YAML.load(yaml), @options)
@layout.compile!
@layout.execute_commands(@layout.generate_commands)
end
end