ensure layout editing is allowed outside of tmux sessions

This commit is contained in:
John Bintz 2012-03-06 14:25:03 -05:00
parent 9ad83268ee
commit bb85ff7641
3 changed files with 36 additions and 19 deletions

View File

@ -12,8 +12,6 @@ module Teamocil
# @param argv [Hash] the command line parameters hash (usually `ARGV`). # @param argv [Hash] the command line parameters hash (usually `ARGV`).
# @param env [Hash] the environment variables hash (usually `ENV`). # @param env [Hash] the environment variables hash (usually `ENV`).
def initialize(argv, env) # {{{ def initialize(argv, env) # {{{
bail "You must be in a tmux session to use teamocil" unless env["TMUX"]
parse_options! argv parse_options! argv
layout_path = File.join("#{env["HOME"]}", ".teamocil") layout_path = File.join("#{env["HOME"]}", ".teamocil")
@ -30,9 +28,12 @@ module Teamocil
if @options[:edit] if @options[:edit]
::FileUtils.touch file unless File.exists?(file) ::FileUtils.touch file unless File.exists?(file)
system("$EDITOR \"#{file}\"")
Kernel.system("$EDITOR \"#{file}\"")
else else
bail "There is no file \"#{file}\"" unless File.exists?(file) bail "There is no file \"#{file}\"" unless File.exists?(file)
bail "You must be in a tmux session to use teamocil" unless env["TMUX"]
parsed_layout = YAML.load_file(file) parsed_layout = YAML.load_file(file)
@layout = Teamocil::Layout.new(parsed_layout, @options) @layout = Teamocil::Layout.new(parsed_layout, @options)
@layout.compile! @layout.compile!

View File

@ -4,23 +4,40 @@ describe Teamocil::CLI do
context "executing" do context "executing" do
before do # {{{ context "not in tmux" do
@fake_env = { "TMUX" => 1, "HOME" => File.join(File.dirname(__FILE__), "fixtures") }
end # }}}
it "creates a layout" do # {{{ before do # {{{
@cli = Teamocil::CLI.new(["sample"], @fake_env) @fake_env = { "TMUX" => 1, "HOME" => File.join(File.dirname(__FILE__), "fixtures") }
@cli.layout.session.name.should == "sample" end # }}}
@cli.layout.session.windows.length.should == 2
@cli.layout.session.windows.first.name.should == "foo"
@cli.layout.session.windows.last.name.should == "bar"
end # }}}
it "lists available layouts" do # {{{ it "should allow editing" do # {{{
@cli = Teamocil::CLI.new(["--list"], @fake_env) FileUtils.stub(:touch)
@cli.layouts.should == ["sample", "sample-2"] Kernel.should_receive(:system).with(any_args())
end # }}}
@cli = Teamocil::CLI.new(["--edit", "my-layout"], @fake_env)
end # }}}
end
context "in tmux" do
before do # {{{
@fake_env = { "TMUX" => 1, "HOME" => File.join(File.dirname(__FILE__), "fixtures") }
end # }}}
it "creates a layout" do # {{{
@cli = Teamocil::CLI.new(["sample"], @fake_env)
@cli.layout.session.name.should == "sample"
@cli.layout.session.windows.length.should == 2
@cli.layout.session.windows.first.name.should == "foo"
@cli.layout.session.windows.last.name.should == "bar"
end # }}}
it "lists available layouts" do # {{{
@cli = Teamocil::CLI.new(["--list"], @fake_env)
@cli.layouts.should == ["sample", "sample-2"]
end # }}}
end
end end
end end

View File

@ -25,5 +25,4 @@ spec = Gem::Specification.new do |s|
s.add_development_dependency "rspec" s.add_development_dependency "rspec"
s.add_development_dependency "yard" s.add_development_dependency "yard"
s.add_development_dependency "maruku" s.add_development_dependency "maruku"
end end