Clean up some code

This commit is contained in:
Rémi Prévost 2011-10-10 08:43:58 -04:00
parent 5719c924b9
commit 600fa879d4

View File

@ -39,16 +39,14 @@ module Teamocil
output << "tmux new-window -n \"#{window["name"]}\"" output << "tmux new-window -n \"#{window["name"]}\""
end end
# Make sure our filters return arrays # Make sure we have a `filters` key and it contains arrays
window["filters"] ||= {} window["filters"] ||= {}
window["filters"]["before"] ||= [] window["filters"]["before"] ||= []
window["filters"]["after"] ||= [] 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 # Create splits
window["splits"].each_with_index do |split, index| window["splits"].each_with_index do |split, split_index|
unless index == 0 unless split_index == 0
if split.include?("width") if split.include?("width")
cmd = "tmux split-window -h -p #{split["width"]}" cmd = "tmux split-window -h -p #{split["width"]}"
elsif split.include?("height") elsif split.include?("height")
@ -60,24 +58,22 @@ module Teamocil
output << cmd output << cmd
end end
# 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 # Wrap all commands around filters
split["cmd"] = window["filters"]["before"] + split["cmd"] + window["filters"]["after"] 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"].unshift "cd \"#{window["root"]}\"" if window.include?("root")
# Execute each split command # Execute each split command
split["cmd"].compact.each do |command| split["cmd"].flatten.compact.each do |command|
output << "tmux send-keys -t #{index} \"#{command}\"" output << "tmux send-keys -t #{split_index} \"#{command}\""
output << "tmux send-keys -t #{index} Enter" output << "tmux send-keys -t #{split_index} Enter"
end end
end end
end end
# Set the focus in the first split
output << "tmux select-pane -t 0" output << "tmux select-pane -t 0"
end # }}} end # }}}