Skip to content

Commit

Permalink
Add support for $TEAMOCIL_PATH (closes #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
remi committed Jun 14, 2012
1 parent a350ff7 commit 32fce43
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/teamocil/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/.my-fancy-layouts-directory/sample-3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
session:
name: sample-3
root: ~
windows:
- name: "foo"
splits:
- cmd: "pwd"
- name: "bar"
splits:
- cmd: "pwd"

0 comments on commit 32fce43

Please sign in to comment.