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

@ -43,6 +43,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) * `name` (the name that will appear in `tmux` statusbar)
* `root` (the directory in which every split will be created) * `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) * `splits` (an array of split items)
#### Example #### Example
@ -50,10 +51,16 @@ If you are not using a top-level `session` key, then the first key of your layou
windows: windows:
- name: my-first-window - name: my-first-window
root: ~/Projects/foo-www 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:
[splits list] [splits list]
- name: my-second-window - name: my-second-window
root: ~/Projects/foo-api root: ~/Projects/foo-api
filters:
after: "rvm use 1.9.2"
splits: splits:
[splits list] [splits list]
- name: my-third-window - name: my-third-window
@ -77,6 +84,9 @@ Every window must define an array of splits that will be created within it. A ve
windows: windows:
- name: my-first-window - name: my-first-window
root: ~/Projects/foo-www root: ~/Projects/foo-www
filters:
before: "rvm use 1.9.2"
after: "echo 'I am done initializing this split.'"
splits: splits:
- cmd: "git status" - cmd: "git status"
- cmd: "bundle exec rails server --port 4000" - cmd: "bundle exec rails server --port 4000"

View File

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

View File

@ -30,12 +30,21 @@ module Teamocil
windows.each_with_index do |window, window_index| 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 if @options.include?(:here) and window_index == 0
output << "tmux rename-window \"#{window["name"]}\"" output << "tmux rename-window \"#{window["name"]}\""
else else
output << "tmux new-window -n \"#{window["name"]}\"" output << "tmux new-window -n \"#{window["name"]}\""
end 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| window["splits"].each_with_index do |split, index|
unless index == 0 unless index == 0
if split.include?("width") if split.include?("width")
@ -52,11 +61,14 @@ module Teamocil
# Support single command splits, but treat it as an array nevertheless # Support single command splits, but treat it as an array nevertheless
split["cmd"] = [split["cmd"]] unless split["cmd"].is_a? Array 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 # If a `root` key exist, start each split in this directory
split["cmd"] = ["cd \"#{window["root"]}\""] + split["cmd"] if window.include?("root") split["cmd"] = ["cd \"#{window["root"]}\""] + split["cmd"] if window.include?("root")
# Execute each split command # 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} \"#{command}\""
output << "tmux send-keys -t #{index} Enter" output << "tmux send-keys -t #{index} Enter"
end end

View File

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