Add support for filters

In your layout files, you can now use the "filters" key in window items,
like so:

    windows:
      - name: my-new-window
        root: ~/Code/foo
        filters:
          before: "sudo bash"
          after:
            - "echo 'Let’s use use ruby-1.9.2 for eachs plit'"
            - "rvm use 1.9.2"
        splits:
          [splits list]
This commit is contained in:
Rémi Prévost 2011-10-07 22:03:51 -04:00
parent e7b6b7ded1
commit 514a13a35d
4 changed files with 30 additions and 8 deletions

View File

@ -31,9 +31,9 @@ You can wrap your entire layout file in a `session` and Teamocil will rename the
#### Example
session:
name: my-awesome-session
windows:
[windows list]
name: my-awesome-session
windows:
[windows list]
### Windows
@ -43,17 +43,24 @@ 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)
* `splits` (an array of split items)
#### Example
windows:
windows:
- name: my-first-window
root: ~/Projects/foo-www
filters:
before:
- "echo 'Lets use ruby-1.9.2 for each split in this window.'"
- "rvm use 1.9.2"
splits:
[splits list]
- name: my-second-window
root: ~/Projects/foo-api
filters:
after: "rvm use 1.9.2"
splits:
[splits list]
- name: my-third-window
@ -74,9 +81,12 @@ Every window must define an array of splits that will be created within it. A ve
#### Example
windows:
windows:
- name: my-first-window
root: ~/Projects/foo-www
filters:
before: "rvm use 1.9.2"
after: "echo 'I am done initializing this split.'"
splits:
- cmd: "git status"
- cmd: "bundle exec rails server --port 4000"

View File

@ -1,5 +1,5 @@
module Teamocil
VERSION = '0.1.9'
VERSION = '0.1.10'
autoload :Layout, "teamocil/layout"
autoload :CLI, "teamocil/cli"
end

View File

@ -30,12 +30,21 @@ module Teamocil
windows.each_with_index do |window, window_index|
# Create a new window unless we used the `--here` option
if @options.include?(:here) and window_index == 0
output << "tmux rename-window \"#{window["name"]}\""
else
output << "tmux new-window -n \"#{window["name"]}\""
end
# Make sure our filters return arrays
window["filters"] ||= {}
window["filters"]["before"] ||= []
window["filters"]["after"] ||= []
window["filters"]["before"] = [window["filters"]["before"]] unless window["filters"]["before"].is_a? Array
window["filters"]["after"] = [window["filters"]["after"]] unless window["filters"]["after"].is_a? Array
# Create splits
window["splits"].each_with_index do |split, index|
unless index == 0
if split.include?("width")
@ -52,11 +61,14 @@ module Teamocil
# Support single command splits, but treat it as an array nevertheless
split["cmd"] = [split["cmd"]] unless split["cmd"].is_a? Array
# Wrap all commands around filters
split["cmd"] = window["filters"]["before"] + split["cmd"] + window["filters"]["after"]
# If a `root` key exist, start each split in this directory
split["cmd"] = ["cd \"#{window["root"]}\""] + split["cmd"] if window.include?("root")
# Execute each split command
split["cmd"].each do |command|
split["cmd"].compact.each do |command|
output << "tmux send-keys -t #{index} \"#{command}\""
output << "tmux send-keys -t #{index} Enter"
end

View File

@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = "teamocil"
s.version = "0.1.9"
s.version = "0.1.10"
s.platform = Gem::Platform::RUBY
s.authors = "Rémi Prévost"
s.email = "remi@exomel.com"