automux 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +6 -0
  3. data/Gemfile.lock +20 -0
  4. data/LICENSE.txt +22 -0
  5. data/VERSION +1 -0
  6. data/automux.gemspec +18 -0
  7. data/bin/automux +22 -0
  8. data/data/automux/blueprints/default.yml +26 -0
  9. data/data/automux/recipes/default.sh.erb +46 -0
  10. data/features/custom_recipes.feature +63 -0
  11. data/features/error_messages.feature +8 -0
  12. data/features/general_usage.feature +180 -0
  13. data/features/managing_blueprints.feature +66 -0
  14. data/features/runtime_options.feature +84 -0
  15. data/features/session_and_window_options.feature +67 -0
  16. data/features/session_hooks.feature +68 -0
  17. data/features/setup_windows.feature +22 -0
  18. data/features/step_definitions/custom_recipes_steps.rb +9 -0
  19. data/features/step_definitions/managing_blueprints_steps.rb +9 -0
  20. data/features/step_definitions/setup_windows_steps.rb +18 -0
  21. data/features/step_definitions/shared_steps.rb +43 -0
  22. data/features/support/env.rb +8 -0
  23. data/features/support/hooks.rb +4 -0
  24. data/features/support/transformations.rb +6 -0
  25. data/lib/automux.rb +9 -0
  26. data/lib/automux/cache.rb +10 -0
  27. data/lib/automux/cache/blueprint.rb +20 -0
  28. data/lib/automux/cache/recipe.rb +27 -0
  29. data/lib/automux/controller.rb +14 -0
  30. data/lib/automux/controller/base.rb +18 -0
  31. data/lib/automux/controller/blueprints.rb +45 -0
  32. data/lib/automux/controller/messages.rb +11 -0
  33. data/lib/automux/controller/recipes.rb +39 -0
  34. data/lib/automux/controller/setup.rb +11 -0
  35. data/lib/automux/controller/support.rb +5 -0
  36. data/lib/automux/controller/support/filters.rb +55 -0
  37. data/lib/automux/controller/support/rendering.rb +54 -0
  38. data/lib/automux/core.rb +11 -0
  39. data/lib/automux/core/base.rb +7 -0
  40. data/lib/automux/core/blueprint.rb +31 -0
  41. data/lib/automux/core/error.rb +15 -0
  42. data/lib/automux/core/hook.rb +26 -0
  43. data/lib/automux/core/option.rb +20 -0
  44. data/lib/automux/core/recipe.rb +12 -0
  45. data/lib/automux/core/support.rb +6 -0
  46. data/lib/automux/core/support/custom_accessors.rb +15 -0
  47. data/lib/automux/core/support/hooks_helper.rb +28 -0
  48. data/lib/automux/core/support/options_helper.rb +18 -0
  49. data/lib/automux/core/tmux.rb +6 -0
  50. data/lib/automux/core/tmux/pane.rb +19 -0
  51. data/lib/automux/core/tmux/session.rb +137 -0
  52. data/lib/automux/core/tmux/window.rb +76 -0
  53. data/lib/automux/initializers.rb +2 -0
  54. data/lib/automux/initializers/custom_hooks.rb +4 -0
  55. data/lib/automux/initializers/setup_caches.rb +3 -0
  56. data/lib/automux/library.rb +5 -0
  57. data/lib/automux/library/mini_erb.rb +22 -0
  58. data/lib/automux/library/yaml_parser.rb +41 -0
  59. data/lib/automux/paths.rb +41 -0
  60. data/lib/automux/setup.rb +0 -0
  61. data/lib/automux/views/blueprints/copy.sh.erb +2 -0
  62. data/lib/automux/views/blueprints/create.sh.erb +2 -0
  63. data/lib/automux/views/blueprints/edit.sh.erb +1 -0
  64. data/lib/automux/views/messages/error.sh.erb +3 -0
  65. data/lib/automux/views/setup/clone_defaults.sh.erb +21 -0
  66. data/test/session_test.rb +16 -0
  67. data/test/support/common_methods.rb +0 -0
  68. data/test/support/factories.rb +13 -0
  69. data/test/support/hash_factory.rb +19 -0
  70. data/test/support/test_helper.rb +7 -0
  71. metadata +136 -0
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .rvmrc
3
+ .bundle
4
+ tmp
5
+ ignored.yml
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ require 'bundler'
3
+
4
+ group :test do
5
+ gem 'cucumber'
6
+ end
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ builder (3.2.0)
5
+ cucumber (1.2.3)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (>= 1.1.3)
8
+ gherkin (~> 2.11.6)
9
+ multi_json (~> 1.3)
10
+ diff-lcs (1.2.1)
11
+ gherkin (2.11.6)
12
+ json (>= 1.7.6)
13
+ json (1.7.7)
14
+ multi_json (1.7.1)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ cucumber
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex Johnson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "automux"
7
+ gem.version = File.read('VERSION').strip.chomp
8
+ gem.authors = ["Alex Johnson"]
9
+ gem.email = ["notalexjohnson@gmail.com"]
10
+ gem.description = %[Automating Tmux Configuration]
11
+ gem.summary = %[Automux can automate tmux sessions by reading configuration from yaml files]
12
+ gem.homepage = "https://github.com/notalex/automux"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ end
@@ -0,0 +1,22 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ lib_path = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
5
+
6
+ require 'automux'
7
+
8
+ args = ARGV.take_while { |argument| argument.match(/^\w/) }
9
+
10
+ case args[0]
11
+ when 'setup'
12
+ Automux::Controller::Setup.new.clone_defaults
13
+ when 'blueprint'
14
+ params = { name: args[2], clone_name: args[3] }
15
+ Automux::Controller::Blueprints.new(params).send(args[1])
16
+ else
17
+ params = {
18
+ blueprint_name: args[0] || 'default',
19
+ recipe_name: args[1] || 'default'
20
+ }
21
+ Automux::Controller::Recipes.new(params).automate
22
+ end
@@ -0,0 +1,26 @@
1
+ name: test
2
+ root: ~/
3
+ flags: -u2
4
+ options:
5
+ status: off
6
+ windows:
7
+ - name: panes
8
+ layout: main-vertical
9
+ panes:
10
+ - irb
11
+ - top
12
+ - ls
13
+ - name: vim
14
+ hooks:
15
+ pre:
16
+ - echo 'Starting vim'
17
+ panes: vim
18
+ - name: custom-indexed-window
19
+ index: 1
20
+ hooks:
21
+ post:
22
+ - echo 'Running <%= name %>'
23
+ - name: optional-window
24
+ opt: '-r'
25
+ panes:
26
+ - echo 'Created optional window'
@@ -0,0 +1,46 @@
1
+ cd <%= root %>
2
+
3
+ - pre_hooks.each do |hook|
4
+ = hook.command
5
+ - end
6
+
7
+ = start_server
8
+ = new_session
9
+
10
+ - options.each do |option|
11
+ = set_option(option)
12
+ - end
13
+
14
+ - windows.each do |window|
15
+ = new_window(window)
16
+ = rename_window(window) if window.name
17
+
18
+ - if window.has_panes?
19
+ = send_keys(window, window.change_root_command) if window.root
20
+
21
+ - window.pre_hooks.each do |hook|
22
+ = send_keys(window, hook.command)
23
+ - end
24
+
25
+ - window.panes.each do |pane|
26
+ = create_pane if pane.index > 0
27
+ = send_keys(window, pane.command)
28
+ - end
29
+
30
+ - window.options.each do |option|
31
+ = window.set_option(option)
32
+ - end
33
+
34
+ - window.post_hooks.each do |hook|
35
+ = send_keys(window, hook.command)
36
+ - end
37
+
38
+ = select_layout(window) if window.layout
39
+ - end
40
+ - end
41
+
42
+ = attach_session
43
+
44
+ - post_hooks.each do |hook|
45
+ = hook.command
46
+ - end
@@ -0,0 +1,63 @@
1
+ Feature: User using a custom recipe
2
+
3
+ Scenario: Simple recipe with no tmux related code
4
+ Given I have the following recipe named "test_recipe"
5
+ """
6
+ echo using the <%= name %> blueprint
7
+ """
8
+ And I have the following blueprint named "test_sample"
9
+ """
10
+ name: test
11
+ windows:
12
+ - panes: vim
13
+ """
14
+ When I invoke Automux with the recipe "test_recipe" and the blueprint "default"
15
+ Then the rendered sequence of shell commands should be
16
+ """
17
+ echo using the test blueprint
18
+ """
19
+
20
+ Scenario: Using a recipe that skips the hooks and options features
21
+ Given I have the following recipe named "test_recipe"
22
+ """
23
+ cd <%= root %>
24
+
25
+ = start_server
26
+ = new_session
27
+
28
+ - windows.each do |window|
29
+ = new_window(window)
30
+
31
+ - window.panes.each do |pane|
32
+ = create_pane if pane.index > 0
33
+ = send_keys(window, pane.command)
34
+ - end
35
+ - end
36
+
37
+ = attach_session
38
+ """
39
+ And I have the following blueprint named "test_sample"
40
+ """
41
+ name: test
42
+ options:
43
+ status: off
44
+ windows:
45
+ - name: vim
46
+ hooks:
47
+ pre: echo Hello
48
+ index: 2
49
+ panes: vim
50
+ """
51
+ When I invoke Automux with the recipe "test_recipe" and the blueprint "test_sample"
52
+ Then the rendered sequence of shell commands should be
53
+ """
54
+ cd .
55
+
56
+ tmux start-server
57
+ tmux new-session -d -s test
58
+
59
+ tmux new-window -t test:2 2> /dev/null
60
+ tmux send-keys -t test:2 "vim" C-m
61
+
62
+ tmux attach-session -t test
63
+ """
@@ -0,0 +1,8 @@
1
+ Feature: Handling various errors with relevant messages
2
+
3
+ Scenario: Trying to use a non existing blueprint
4
+ When I invoke Automux with the blueprint "test_sample"
5
+ Then the rendered sequence of shell commands should contain
6
+ """
7
+ echo No matching blueprint found
8
+ """
@@ -0,0 +1,180 @@
1
+ Feature: User entering a blueprint from commandline
2
+ As an Automux user
3
+ I want to run Automux with a blueprint
4
+ In order to run the shell commands matching the given blueprint
5
+
6
+ Scenario: A 4 window blueprint with some fixed indexes and subpanes
7
+ Given I have the following blueprint named "test_sample"
8
+ """
9
+ name: test
10
+ root: ~/projects
11
+ windows:
12
+ - name: editor
13
+ layout: main-vertical
14
+ panes:
15
+ - ls
16
+ - top
17
+ - pwd
18
+ - name: htop
19
+ panes: htop
20
+ - name: tester
21
+ index: 1
22
+ panes:
23
+ - pwd
24
+ - name: zero
25
+ index: 0
26
+ panes: [pwd, echo hello]
27
+ """
28
+ When I invoke Automux with the blueprint "test_sample"
29
+ Then the rendered sequence of shell commands should be
30
+ """
31
+ cd ~/projects
32
+
33
+ tmux start-server
34
+ tmux new-session -d -s test
35
+
36
+ tmux new-window -t test:2 2> /dev/null
37
+ tmux rename-window -t test:2 editor
38
+
39
+ tmux send-keys -t test:2 "ls" C-m
40
+ tmux split-window
41
+ tmux send-keys -t test:2 "top" C-m
42
+ tmux split-window
43
+ tmux send-keys -t test:2 "pwd" C-m
44
+ tmux select-layout -t test:2 main-vertical
45
+
46
+ tmux new-window -t test:3 2> /dev/null
47
+ tmux rename-window -t test:3 htop
48
+ tmux send-keys -t test:3 "htop" C-m
49
+
50
+ tmux new-window -t test:1 2> /dev/null
51
+ tmux rename-window -t test:1 tester
52
+ tmux send-keys -t test:1 "pwd" C-m
53
+
54
+ tmux new-window -t test:0 2> /dev/null
55
+ tmux rename-window -t test:0 zero
56
+ tmux send-keys -t test:0 "pwd" C-m
57
+ tmux split-window
58
+ tmux send-keys -t test:0 "echo hello" C-m
59
+
60
+ tmux attach-session -t test
61
+ """
62
+
63
+ Scenario: Windows with clashing index values
64
+ Given I have the following blueprint named "test_sample"
65
+ """
66
+ name: test
67
+ root: '~'
68
+ windows:
69
+ - name: editor
70
+ panes: vim
71
+ index: 1
72
+ - name: top
73
+ panes: top
74
+ index: 1
75
+ """
76
+ When I invoke Automux with the blueprint "test_sample"
77
+ Then the rendered sequence of shell commands should be
78
+ """
79
+ cd ~
80
+
81
+ tmux start-server
82
+ tmux new-session -d -s test
83
+
84
+ tmux new-window -t test:1 2> /dev/null
85
+ tmux rename-window -t test:1 editor
86
+ tmux send-keys -t test:1 "vim" C-m
87
+
88
+ tmux new-window -t test:0 2> /dev/null
89
+ tmux rename-window -t test:0 top
90
+ tmux send-keys -t test:0 "top" C-m
91
+
92
+ tmux attach-session -t test
93
+ """
94
+
95
+ Scenario: Only session name is provided
96
+ Given I have the following blueprint named "test_sample"
97
+ """
98
+ name: window-less
99
+ """
100
+ When I invoke Automux with the blueprint "test_sample"
101
+ Then the rendered sequence of shell commands should be
102
+ """
103
+ cd .
104
+
105
+ tmux start-server
106
+ tmux new-session -d -s window-less
107
+
108
+ tmux attach-session -t window-less
109
+ """
110
+
111
+ Scenario: Providing no name for a window
112
+ Given I have the following blueprint named "test_sample"
113
+ """
114
+ name: name-less
115
+ windows:
116
+ - panes: git pull origin master
117
+ """
118
+ When I invoke Automux with the blueprint "test_sample"
119
+ Then the rendered sequence of shell commands should be
120
+ """
121
+ cd .
122
+
123
+ tmux start-server
124
+ tmux new-session -d -s name-less
125
+
126
+ tmux new-window -t name-less:0 2> /dev/null
127
+ tmux send-keys -t name-less:0 "git pull origin master" C-m
128
+
129
+ tmux attach-session -t name-less
130
+ """
131
+
132
+ Scenario: Providing flags for tmux
133
+ Given I have the following blueprint named "test_sample"
134
+ """
135
+ name: flagged
136
+ flags: -u2
137
+ windows:
138
+ - panes: vim
139
+ """
140
+ When I invoke Automux with the blueprint "test_sample"
141
+ Then the rendered sequence of shell commands should be
142
+ """
143
+ cd .
144
+
145
+ tmux start-server
146
+ tmux -u2 new-session -d -s flagged
147
+
148
+ tmux new-window -t flagged:0 2> /dev/null
149
+ tmux send-keys -t flagged:0 "vim" C-m
150
+
151
+ tmux -u2 attach-session -t flagged
152
+ """
153
+
154
+ Scenario: Windows with separate roots
155
+ Given I have the following blueprint named "test_sample"
156
+ """
157
+ name: test
158
+ root: '~'
159
+ windows:
160
+ - panes: vim
161
+ root: 'projects'
162
+ - panes: top
163
+ """
164
+ When I invoke Automux with the blueprint "test_sample"
165
+ Then the rendered sequence of shell commands should be
166
+ """
167
+ cd ~
168
+
169
+ tmux start-server
170
+ tmux new-session -d -s test
171
+
172
+ tmux new-window -t test:0 2> /dev/null
173
+ tmux send-keys -t test:0 "cd projects" C-m
174
+ tmux send-keys -t test:0 "vim" C-m
175
+
176
+ tmux new-window -t test:1 2> /dev/null
177
+ tmux send-keys -t test:1 "top" C-m
178
+
179
+ tmux attach-session -t test
180
+ """
@@ -0,0 +1,66 @@
1
+ Feature: Creating, Cloning, Editing and Deleting Blueprints
2
+
3
+ Scenario: Editing a blueprint
4
+ Given I have the following blueprint named "test_sample"
5
+ """
6
+ name: created-using-cuke
7
+ windows:
8
+ - panes: ls
9
+ """
10
+ When I invoke Automux to "edit" the blueprint "test_sample"
11
+ Then the rendered sequence of shell commands should be
12
+ """
13
+ $EDITOR $HOME/.automux/blueprints/test_sample.yml
14
+ """
15
+
16
+ Scenario: Creating a new blueprint
17
+ When I invoke Automux to "create" the blueprint "test_sample"
18
+ Then the rendered sequence of shell commands should be
19
+ """
20
+ cp $HOME/.automux/blueprints/default.yml $HOME/.automux/blueprints/test_sample.yml
21
+ $EDITOR $HOME/.automux/blueprints/test_sample.yml
22
+ """
23
+
24
+ Scenario: Copying a blueprint
25
+ When I call Automux to "copy" the blueprint "default" as "test_sample"
26
+ Then the rendered sequence of shell commands should be
27
+ """
28
+ cp $HOME/.automux/blueprints/default.yml $HOME/.automux/blueprints/test_sample.yml
29
+ echo default.yml copied
30
+ """
31
+
32
+ Scenario: Using an alias to copy blueprint
33
+ When I call Automux to "cp" the blueprint "default" as "test_sample"
34
+ Then the rendered sequence of shell commands should be
35
+ """
36
+ cp $HOME/.automux/blueprints/default.yml $HOME/.automux/blueprints/test_sample.yml
37
+ echo default.yml copied
38
+ """
39
+
40
+ Scenario: Deleting a blueprint
41
+ Given I have the following blueprint named "test_sample"
42
+ """
43
+ name: created-using-cuke
44
+ windows:
45
+ - panes: ls
46
+ """
47
+ When I invoke Automux to "delete" the blueprint "test_sample"
48
+ Then the rendered sequence of shell commands should be
49
+ """
50
+ rm $HOME/.automux/blueprints/test_sample.yml
51
+ echo test_sample.yml deleted
52
+ """
53
+
54
+ Scenario: Deleting blueprint using the alias
55
+ Given I have the following blueprint named "test_sample"
56
+ """
57
+ name: created-using-cuke
58
+ windows:
59
+ - panes: ls
60
+ """
61
+ When I invoke Automux to "rm" the blueprint "test_sample"
62
+ Then the rendered sequence of shell commands should be
63
+ """
64
+ rm $HOME/.automux/blueprints/test_sample.yml
65
+ echo test_sample.yml deleted
66
+ """