diff --git a/README.md b/README.md index 53b15b0..1080451 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,12 @@ $ teamocil sample * `--here` opens the session in the current window, do not create an empty first window. * `--layout` takes a custom file path to a YAML layout file. * `--edit` opens the layout file (whether or not `--layout` is used) with `$EDITOR`. -* `--list` lists all available layouts in `./.teamocil`. +* `--list` lists all available layouts in `./.teamocil` or `$TEAMOCIL_PATH`. * `--show` show the layout content instead of executing it. ## Layout file structure -A layout file is a single YAML file located in `~/.teamocil` (eg. `~/.teamocil/my-project.yml`). +A layout file is a single YAML file located in `~/.teamocil` or `$TEAMOCIL_PATH` (eg. `~/.teamocil/my-project.yml`). ### Session diff --git a/lib/teamocil/cli.rb b/lib/teamocil/cli.rb index e668871..2973b95 100644 --- a/lib/teamocil/cli.rb +++ b/lib/teamocil/cli.rb @@ -13,7 +13,7 @@ class CLI # @param env [Hash] the environment variables hash (usually `ENV`). def initialize(argv, env) # {{{ parse_options! argv - layout_path = File.join("#{env["HOME"]}", ".teamocil") + layout_path = env["TEAMOCIL_PATH"] || File.join("#{env["HOME"]}", ".teamocil") if @options.include?(:list) @layouts = get_layouts(layout_path) diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 765eaa0..6285996 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -62,6 +62,16 @@ Teamocil::CLI.new(["--show", "sample"], @fake_env) end # }}} + it "looks only in the $TEAMOCIL_PATH environment variable for layouts" do # {{{ + @fake_env = { "TMUX" => 1, "HOME" => File.join(File.dirname(__FILE__), "fixtures"), "TEAMOCIL_PATH" => File.join(File.dirname(__FILE__), "fixtures/.my-fancy-layouts-directory") } + + @cli = Teamocil::CLI.new(["sample-3"], @fake_env) + @cli.layout.session.name.should == "sample-3" + + lambda { @cli = Teamocil::CLI.new(["sample"], @fake_env) }.should raise_error SystemExit + Teamocil::CLI.messages.should include("There is no file \"#{@fake_env["TEAMOCIL_PATH"]}/sample.yml\"") + end # }}} + end end diff --git a/spec/fixtures/.my-fancy-layouts-directory/sample-3.yml b/spec/fixtures/.my-fancy-layouts-directory/sample-3.yml new file mode 100644 index 0000000..b2c1cf0 --- /dev/null +++ b/spec/fixtures/.my-fancy-layouts-directory/sample-3.yml @@ -0,0 +1,10 @@ +session: + name: sample-3 + root: ~ + windows: + - name: "foo" + splits: + - cmd: "pwd" + - name: "bar" + splits: + - cmd: "pwd"