tlux 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/tlux CHANGED
@@ -17,6 +17,11 @@ if ARGV.any?
17
17
  rescue Tlux::Config::FileNotFound
18
18
  puts "Tlux config file not found #{ARGV[0]}"
19
19
  exit 1
20
+
21
+ rescue Tlux::CommandNotFoundError
22
+ puts "Command not available"
23
+ exit 1
24
+
20
25
  end
21
26
  else
22
27
 
@@ -24,9 +29,9 @@ else
24
29
  Tlux version: #{Tlux::VERSION}
25
30
 
26
31
  Usage:
27
- tlux new <config_name> : creates a new a config file and opens it in your editor
28
- tlux list : lists the currently available configs
29
- tlux run <config_name> : attach a tmux session with the given config name
32
+ tlux open <config_name> : open the config file in your $EDITOR, creates config if it doesn't already exist
33
+ tlux list : lists the currently available configs
34
+ tlux run <config_name> : attach a tmux session with the given config name
30
35
  EOF
31
36
  end
32
37
 
data/lib/tlux.rb CHANGED
@@ -5,6 +5,7 @@ require "fileutils"
5
5
  module Tlux
6
6
  TEMPLATES_PATH = File.join(File.dirname(__FILE__), 'tlux', 'templates')
7
7
  class EditorNotDefinedError < StandardError ; end
8
+ class CommandNotFoundError < StandardError ; end
8
9
  end
9
10
 
10
11
  require "tlux/splitable"
data/lib/tlux/commands.rb CHANGED
@@ -1,8 +1,22 @@
1
1
  module Tlux
2
2
  module Commands
3
- def self.run(command_name, args = [])
4
- command = self.const_get("#{command_name.capitalize}Command").new(*args)
5
- command.run
3
+ extend self
4
+
5
+ def run(command_name, args = [])
6
+ raise Tlux::CommandNotFoundError unless available?(command_name)
7
+ name_to_constant(command_name).new(*args).run
8
+ end
9
+
10
+ private
11
+
12
+ def available?(command_name)
13
+ !!name_to_constant(command_name)
14
+ rescue NameError
15
+ false
16
+ end
17
+
18
+ def name_to_constant(command_name)
19
+ self.const_get("#{command_name.capitalize}Command")
6
20
  end
7
21
  end
8
22
  end
@@ -10,4 +24,4 @@ end
10
24
  require 'tlux/commands/base'
11
25
  require 'tlux/commands/list_command'
12
26
  require 'tlux/commands/run_command'
13
- require 'tlux/commands/new_command'
27
+ require 'tlux/commands/open_command'
@@ -1,6 +1,6 @@
1
1
  module Tlux
2
2
  module Commands
3
- class NewCommand < Tlux::Commands::Base
3
+ class OpenCommand < Tlux::Commands::Base
4
4
  attr_reader :config_name
5
5
 
6
6
  def initialize(config_name)
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module Tlux
2
4
  module Commands
3
5
  class RunCommand < Tlux::Commands::Base
@@ -11,21 +13,23 @@ module Tlux
11
13
  def run
12
14
  parser = Tlux::Config::Parser.from_file(config_file_path)
13
15
  parser.parse!
14
- parser.session.name = config_name
15
-
16
- write_output Tlux::Config::Generator.new(parser.session).generate!
16
+ parser.session.name = session_name
17
17
 
18
- exec "tmux -f #{output_path} attach"
18
+ exec Tlux::Config::Generator.new(parser.session).generate!
19
19
  end
20
20
 
21
21
  private
22
22
 
23
+ def session_name
24
+ Pathname.new(Dir.pwd).basename.replace(/\./, '-').replace(/\:/, '-')
25
+ end
26
+
23
27
  def config_file_path
24
28
  File.join(config_path, config_name)
25
29
  end
26
30
 
27
31
  def output_path
28
- File.join(generated_path, config_name)
32
+ File.join(generated_path, session_name)
29
33
  end
30
34
 
31
35
  def write_output(output)
@@ -1,27 +1,31 @@
1
- # This file is automatically generated by tlux and should not be manually edited
2
- # To make changes to your config edit the file at ~/.tlux/<%= name %>
1
+ tmux has-session <%= name %>
2
+ if [ $? != 0 ]
3
+ then
4
+ tmux new-session -s <%= name %> -n <%= windows.first.name %> -d
5
+ tmux send-keys -t <%= name %> 'cd <%= dir %>' C-m
3
6
 
4
- source-file ~/.tmux.conf
7
+ <% windows.each_with_index do |window, window_idx| %>
8
+ <% if window_idx > 0 %>
9
+ tmux new-window -n <%= window.name %> -t <%= name %>
10
+ <% end %>
5
11
 
6
- new-session -s <%= name %> -n <%= windows.first.name %> -d
7
- send-keys -t <%= name %> 'cd <%= dir %>' C-m
12
+ tmux send-keys -t <%= name %> 'cd <%= dir %>' C-m
8
13
 
9
- <% windows.each_with_index do |window, window_idx| %>
10
- <% if window_idx > 0 %>
11
- new-window -n <%= window.name %> -t <%= name %>
12
- <% end %>
14
+ <% window.commands.each do |command| %>
15
+ tmux send-keys -t <%= name %> '<%= command %>' C-m
16
+ <% end %>
13
17
 
14
- send-keys -t <%= name %> 'cd <%= dir %>' C-m
18
+ <% window.panes.each_with_index do |pane, pane_idx| %>
19
+ tmux split-window <%= pane.orientation %> <%= pane.size %> -t <%= name %>
20
+ tmux send-keys -t <%= name %>:<%= window_idx + 1 %>.<%= pane_idx + 1 %> 'cd <%= dir %>' C-m
15
21
 
16
- <% window.commands.each do |command| %>
17
- send-keys -t <%= name %> '<%= command %>' C-m
18
- <% end %>
19
-
20
- <% window.panes.each_with_index do |pane, pane_idx| %>
21
- split-window <%= pane.orientation %> <%= pane.size %> -t <%= name %>
22
- send-keys -t <%= name %>:<%= window_idx + 1 %>.<%= pane_idx + 1 %> 'cd <%= dir %>' C-m
23
- <% pane.commands.each do |command| %>
24
- send-keys -t <%= name %>:<%= window_idx + 1 %>.<%= pane_idx + 1 %> '<%= command %>' C-m
22
+ <% pane.commands.each do |command| %>
23
+ tmux send-keys -t <%= name %>:<%= window_idx + 1 %>.<%= pane_idx + 1 %> '<%= command %>' C-m
24
+ <% end %>
25
25
  <% end %>
26
26
  <% end %>
27
- <% end %>
27
+
28
+ tmux select-window -t <%= name %>:1
29
+
30
+ fi
31
+ tmux attach -t <%= name %>
data/lib/tlux/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tlux
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tlux::Commands do
4
+ describe ".run" do
5
+ let(:command) { double(Tlux::Commands::RunCommand, run: true) }
6
+ let(:args) { [1,2,3] }
7
+
8
+ before do
9
+ Tlux::Commands::RunCommand.stub!(:new).and_return(command)
10
+ end
11
+
12
+ context "with an available command" do
13
+ it "should instantiate a command and run it" do
14
+ command.should_receive(:run)
15
+ Tlux::Commands::RunCommand.should_receive(:new).with(*args)
16
+ Tlux::Commands.run('run', args)
17
+ end
18
+ end
19
+
20
+ context "with an unavailable command" do
21
+ it "should raise a CommandNotFoundError" do
22
+ expect {
23
+ Tlux::Commands.run('foo')
24
+ }.to raise_error(Tlux::CommandNotFoundError)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,9 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Tlux::Commands::NewCommand do
3
+ describe Tlux::Commands::OpenCommand do
4
4
  describe "#run" do
5
5
  let(:config_name) { 'foo' }
6
- subject { Tlux::Commands::NewCommand.new(config_name) }
6
+ subject { Tlux::Commands::OpenCommand.new(config_name) }
7
7
 
8
8
  before :each do
9
9
  FakeFS.activate!
data/tlux.gemspec CHANGED
@@ -16,5 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Tlux::VERSION
17
17
 
18
18
  gem.add_development_dependency('rspec')
19
+ gem.add_development_dependency('rake')
19
20
  #gem.add_development_dependency('fakefs')
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tlux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000 Z
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70260310518360 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,28 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70260310518360
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
25
46
  description: Luxurious tmux configuration
26
47
  email:
27
48
  - oliver.nightingale1@gmail.com
@@ -42,7 +63,7 @@ files:
42
63
  - lib/tlux/commands.rb
43
64
  - lib/tlux/commands/base.rb
44
65
  - lib/tlux/commands/list_command.rb
45
- - lib/tlux/commands/new_command.rb
66
+ - lib/tlux/commands/open_command.rb
46
67
  - lib/tlux/commands/run_command.rb
47
68
  - lib/tlux/commands/start.rb
48
69
  - lib/tlux/commands/start_command.rb
@@ -57,8 +78,9 @@ files:
57
78
  - lib/tlux/version.rb
58
79
  - lib/tlux/window.rb
59
80
  - spec/commands/base_spec.rb
81
+ - spec/commands/commands_spec.rb
60
82
  - spec/commands/list_command_spec.rb
61
- - spec/commands/new_command_spec.rb
83
+ - spec/commands/open_command_spec.rb
62
84
  - spec/commands/run_command_spec.rb
63
85
  - spec/config/generator_spec.rb
64
86
  - spec/config/parser_spec.rb
@@ -82,22 +104,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
104
  - - ! '>='
83
105
  - !ruby/object:Gem::Version
84
106
  version: '0'
107
+ segments:
108
+ - 0
109
+ hash: 628163894706265299
85
110
  required_rubygems_version: !ruby/object:Gem::Requirement
86
111
  none: false
87
112
  requirements:
88
113
  - - ! '>='
89
114
  - !ruby/object:Gem::Version
90
115
  version: '0'
116
+ segments:
117
+ - 0
118
+ hash: 628163894706265299
91
119
  requirements: []
92
120
  rubyforge_project:
93
- rubygems_version: 1.8.11
121
+ rubygems_version: 1.8.23
94
122
  signing_key:
95
123
  specification_version: 3
96
124
  summary: Luxurious tmux configuration
97
125
  test_files:
98
126
  - spec/commands/base_spec.rb
127
+ - spec/commands/commands_spec.rb
99
128
  - spec/commands/list_command_spec.rb
100
- - spec/commands/new_command_spec.rb
129
+ - spec/commands/open_command_spec.rb
101
130
  - spec/commands/run_command_spec.rb
102
131
  - spec/config/generator_spec.rb
103
132
  - spec/config/parser_spec.rb