Add --here option to create the first window in the current window

This commit is contained in:
Rémi Prévost 2011-02-16 10:36:09 -05:00
parent 9f1b573a99
commit 34c7ec5649
4 changed files with 37 additions and 12 deletions

View File

@ -1,13 +1,34 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
def bail(msg)
puts msg
exit(1)
end
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'yaml' require 'yaml'
require 'teamocil' require 'teamocil'
require 'optparse'
bail "You must be in a tmux session to use teamocil" unless ENV["TMUX"]
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: teamocil [options] <layout>
Options:
"
opts.on("--here", "Set up the first window in the current window") do |safe|
options[:here] = true
end
if ENV["TMUX"] == nil
puts "You must be in a tmux session to use teamocil"
else
layout = Teamocil::Layout.new(ARGV[0], File.join("#{ENV["HOME"]}/.teamocil", "#{ARGV[0]}.yml"))
layout.to_tmux
end end
opts.parse!
file = File.join("#{ENV["HOME"]}/.teamocil", "#{ARGV[0]}.yml")
bail "There is no file \"#{file}\"" unless File.exists?(file)
layout = Teamocil::Layout.new(file, options)
layout.to_tmux

View File

@ -1,4 +1,4 @@
module Teamocil module Teamocil
VERSION = '0.1.2' VERSION = '0.1.4'
autoload :Layout, "teamocil/layout" autoload :Layout, "teamocil/layout"
end end

View File

@ -1,11 +1,11 @@
module Teamocil module Teamocil
class Layout class Layout
attr_accessor :config, :name attr_accessor :layout, :options
def initialize(name, file) # {{{ def initialize(file, options) # {{{
@layout = YAML.load_file(file) @layout = YAML.load_file(file)
@name = name @options = options
end # }}} end # }}}
def to_tmux # {{{ def to_tmux # {{{
@ -16,9 +16,13 @@ module Teamocil
def generate_commands # {{{ def generate_commands # {{{
output = [] output = []
@layout["windows"].each do |window| @layout["windows"].each_with_index do |window, window_index|
output << "tmux new-window -n #{window["name"]}" if options.include?(:here) and window_index == 0
output << "tmux rename-window #{window["name"]}"
else
output << "tmux new-window -n #{window["name"]}"
end
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")

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.2" s.version = "0.1.4"
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"