From 882311321995d43198476064a8badbcae2fd1b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Re=CC=81mi=20Pre=CC=81vost?= Date: Tue, 19 Jul 2011 20:47:16 -0400 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20a=20=E2=80=9Croot?= =?UTF-8?q?=E2=80=9D=20window=20key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.mkd | 7 ++++--- lib/teamocil/layout.rb | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.mkd b/README.mkd index e28ca49..922801d 100644 --- a/README.mkd +++ b/README.mkd @@ -23,11 +23,12 @@ Teamocil is a tool used to automatically create sessions, windows and splits in name: sample-session windows: - name: sample-window + root: ~/Code/sample/www splits: - - cmd: cd ~/Code/sample/www - cmd: - - cd ~/Code/sample/www - - rails s + - ls -la + - git status + - cmd: rails server --port 3000 width: 50 - cmd: memcached -p 11211 -vv height: 25 diff --git a/lib/teamocil/layout.rb b/lib/teamocil/layout.rb index 7cd5d68..1c118c3 100644 --- a/lib/teamocil/layout.rb +++ b/lib/teamocil/layout.rb @@ -26,10 +26,11 @@ module Teamocil windows.each_with_index do |window, window_index| if options.include?(:here) and window_index == 0 - output << "tmux rename-window #{window["name"]}" + output << "tmux rename-window \"#{window["name"]}\"" else - output << "tmux new-window -n #{window["name"]}" + output << "tmux new-window -n \"#{window["name"]}\"" end + window["splits"].each_with_index do |split, index| unless index == 0 if split.include?("width") @@ -43,7 +44,13 @@ module Teamocil end end + # Support single command splits, but treat it as an array nevertheless split["cmd"] = [split["cmd"]] unless split["cmd"].is_a? Array + + # 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| output << "tmux send-keys -t #{index} \"#{command}\"" output << "tmux send-keys -t #{index} Enter"