Skip to content

Commit

Permalink
Add clear window option
Browse files Browse the repository at this point in the history
  • Loading branch information
remi committed Aug 27, 2012
1 parent b04cb6c commit 1bb7f02
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ If you are not using a top-level `session` key, then the first key of your layou
* `name` (the name that will appear in `tmux` statusbar)
* `root` (the directory in which every split will be created)
* `filters` (a hash of `before` and `after` commands to run for each split)
* `clear` (whether or not to prepend a `clear` command before the `before` filters list)
* `splits` (an array of split items)
* `options` (a hash of tmux options, see `man tmux` for a list)

Expand All @@ -59,6 +60,7 @@ If you are not using a top-level `session` key, then the first key of your layou
```yaml
windows:
- name: "my-first-window"
clear: true
options:
synchronize-panes: true
root: "~/Projects/foo-www"
Expand Down
2 changes: 1 addition & 1 deletion lib/teamocil/layout/split.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def generate_commands # {{{
end

# Wrap all commands around filters
@cmd = [@window.filters["before"]] + [@cmd] + [@window.filters["after"]]
@cmd = [@window.filters["before"]] + [@window.clear] + [@cmd] + [@window.filters["after"]]

# If a `root` key exist, start each split in this directory
@cmd.unshift "cd \"#{@window.root}\"" unless @window.root.nil?
Expand Down
3 changes: 2 additions & 1 deletion lib/teamocil/layout/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Layout

# This class represents a window within tmux
class Window
attr_reader :filters, :root, :splits, :options, :index, :name
attr_reader :filters, :root, :splits, :options, :index, :name, :clear

# Initialize a new tmux window
#
Expand All @@ -13,6 +13,7 @@ class Window
def initialize(session, index, attrs={}) # {{{
@name = attrs["name"] || "teamocil-window-#{index+1}"
@root = attrs["root"] || "."
@clear = attrs["clear"] == true ? "clear" : nil
@options = attrs["options"] || {}

@splits = attrs["splits"] || []
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
two-windows:
windows:
- name: "foo"
clear: true
root: "/foo"
splits:
- cmd: "echo 'foo'"
Expand Down
12 changes: 12 additions & 0 deletions spec/layout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
session.windows[0].root.should == "/foo"
session.windows[1].root.should == "/bar"
end # }}}

it "creates windows with clear option" do # {{{
session = @layout.compile!
session.windows[0].clear.should == "clear"
session.windows[1].clear.should be_nil
end # }}}
end # }}}

describe "splits" do # {{{
Expand Down Expand Up @@ -138,6 +144,12 @@
commands.length.should == 2
commands.first.should == "tmux send-keys -t 0 \"export TEAMOCIL=1 && cd \"/bar\" && echo 'bar' && echo 'bar in an array'\""
commands.last.should == "tmux send-keys -t 0 Enter"

session = @layout.compile!
commands = session.windows.first.splits[0].generate_commands
commands.length.should == 2
commands.first.should == "tmux send-keys -t 0 \"export TEAMOCIL=1 && cd \"/foo\" && clear && echo 'foo'\""
commands.last.should == "tmux send-keys -t 0 Enter"
end # }}}

it "should generate window commands" do #{{{
Expand Down

0 comments on commit 1bb7f02

Please sign in to comment.