Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new-window command functionality #145

Merged
merged 21 commits into from
May 16, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tmuxp/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ def new_window(self,
window_name=None,
start_directory=None,
attach=True,
window_index=''):
window_index='',
window_command=None):
"""Return :class:`Window` from ``$ tmux new-window``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the docstrings (:param window_index: description, so on) for these params?


.. note::
Expand Down Expand Up @@ -177,6 +178,9 @@ def new_window(self,
'-t%s:%s' % (self.get('session_id'), window_index),
)

if window_command:
window_args += (window_command,)

proc = self.cmd('new-window', *window_args)

if proc.stderr:
Expand Down
25 changes: 25 additions & 0 deletions tmuxp/testsuite/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,31 @@ def test_window_options(self):
window_count += 1
w.select_layout(wconf['layout'])

def test_window_command(self):
yaml_config = """
session_name: test window options
start_directory: '~'
windows:
- layout: main-horizontal
options:
main-pane-height: 5
panes:
- pane
- pane
- pane
window_name: editor
window_command: test_command
"""
s = self.session
sconfig = kaptan.Kaptan(handler='yaml')
sconfig = sconfig.import_config(yaml_config).get()
sconfig = config.expand(sconfig)

builder = WorkspaceBuilder(sconf=sconfig)

wc_config = builder.sconf.get('windows')[0].get('window_command')
self.assertEqual(wc_config, 'test_command')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are intended to be integration tests in the truest sense of the word. See .travis.yml.

We have a minimum tmux version we officially support (though we can bump it of course). I'd like to be sure that this behavior would work on older versions.

Try something like this:

diff --git a/tmuxp/testsuite/workspacebuilder.py b/tmuxp/testsuite/workspacebuilder.py
index 253834e..a8b79dc 100644
--- a/tmuxp/testsuite/workspacebuilder.py
+++ b/tmuxp/testsuite/workspacebuilder.py
@@ -266,7 +266,7 @@ class WindowOptions(TmuxTestCase):
           - pane
           - pane
           window_name: editor
-          window_shell: test_command
+          window_shell: top
         """
         s = self.session
         sconfig = kaptan.Kaptan(handler='yaml')
@@ -277,7 +277,14 @@ class WindowOptions(TmuxTestCase):

         for w, wconf in builder.iter_create_windows(s):
             if 'window_shell' in wconf:
-                self.assertEqual(wconf['window_shell'], text_type('test_command'))
+                self.assertEqual(wconf['window_shell'], text_type('top'))
+            for i in range(10):
+                self.session.server._update_windows()
+                if w['window_name'] != 'top':
+                    break
+                time.sleep(.2)
+
+            self.assertNotEqual(w.get('window_name'), text_type('top'))


 class EnvironmentVariables(TmuxTestCase):
@@ -305,7 +312,7 @@ class EnvironmentVariables(TmuxTestCase):

         self.assertEqual('BAR', self.session.show_environment('FOO'))
         self.assertEqual('/tmp', self.session.show_environment('PATH'))
-        
+
 class WindowAutomaticRename(TmuxTestCase):

     yaml_config = """


class EnvironmentVariables(TmuxTestCase):

Expand Down
6 changes: 6 additions & 0 deletions tmuxp/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,17 @@ def iter_create_windows(self, s):
else:
sd = None

if 'window_command' in wconf:
wc = wconf['window_command']
else:
wc = None

w = s.new_window(
window_name=window_name,
start_directory=sd,
attach=False, # do not move to the new window
window_index=wconf.get('window_index', ''),
window_command=wc,
)

if i == int(1) and w1: # if first window, use window 1
Expand Down