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:
parent
e7b6b7ded1
commit
514a13a35d
20
README.md
20
README.md
@ -31,9 +31,9 @@ You can wrap your entire layout file in a `session` and Teamocil will rename the
|
|||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
session:
|
session:
|
||||||
name: my-awesome-session
|
name: my-awesome-session
|
||||||
windows:
|
windows:
|
||||||
[windows list]
|
[windows list]
|
||||||
|
|
||||||
### Windows
|
### 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)
|
* `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
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
- name: my-first-window
|
- name: my-first-window
|
||||||
root: ~/Projects/foo-www
|
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:
|
||||||
[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
|
||||||
@ -74,9 +81,12 @@ Every window must define an array of splits that will be created within it. A ve
|
|||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
|
|
||||||
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"
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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"
|
||||||
|
Loading…
Reference in New Issue
Block a user