From 514a13a35db5669ca0799d00b19a5dc1c2521947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81mi=20Pre=CC=81vost?= Date: Fri, 7 Oct 2011 22:03:51 -0400 Subject: [PATCH] Add support for filters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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] --- README.md | 20 +++++++++++++++----- lib/teamocil.rb | 2 +- lib/teamocil/layout.rb | 14 +++++++++++++- teamocil.gemspec | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b78180d..bd9c8ab 100644 --- a/README.md +++ b/README.md @@ -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 'Let’s 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" diff --git a/lib/teamocil.rb b/lib/teamocil.rb index 7ba3111..c5a15de 100644 --- a/lib/teamocil.rb +++ b/lib/teamocil.rb @@ -1,5 +1,5 @@ module Teamocil - VERSION = '0.1.9' + VERSION = '0.1.10' autoload :Layout, "teamocil/layout" autoload :CLI, "teamocil/cli" end diff --git a/lib/teamocil/layout.rb b/lib/teamocil/layout.rb index 0ed2394..530ce79 100644 --- a/lib/teamocil/layout.rb +++ b/lib/teamocil/layout.rb @@ -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 diff --git a/teamocil.gemspec b/teamocil.gemspec index 981f406..a881438 100644 --- a/teamocil.gemspec +++ b/teamocil.gemspec @@ -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"