Permalink
Browse files

add window_index option

includes docs and tests
  • Loading branch information...
1 parent 630bb09 commit 94d12c5b3501911c896efb440c8fe2705baed3bc Stratos Moros committed Dec 5, 2013
View
@@ -179,7 +179,25 @@ JSON
.. literalinclude:: ../examples/focus-window-and-panes.json
:language: json
-
+
+Window Index
+------------
+
+You can specify a window's index using the ``window_index`` property. Windows
+without ``window_index`` will use the lowest available window index.
+
+YAML
+""""
+
+.. literalinclude:: ../examples/window-index.yaml
+ :language: yaml
+
+JSON
+""""
+
+.. literalinclude:: ../examples/window-index.json
+ :language: json
+
Automatic Rename
----------------
View
@@ -0,0 +1,24 @@
+{
+ "windows": [
+ {
+ "panes": [
+ "echo \"this window's index will be zero\""
+ ],
+ "window_name": "zero"
+ },
+ {
+ "panes": [
+ "echo \"this window's index will be five\""
+ ],
+ "window_index": 5,
+ "window_name": "five"
+ },
+ {
+ "panes": [
+ "echo \"this window's index will be one\""
+ ],
+ "window_name": "one"
+ }
+ ],
+ "session_name": "Window index example"
+}
View
@@ -0,0 +1,12 @@
+session_name: Window index example
+windows:
+ - window_name: zero
+ panes:
+ - echo "this window's index will be zero"
+ - window_name: five
+ panes:
+ - echo "this window's index will be five"
+ window_index: 5
+ - window_name: one
+ panes:
+ - echo "this window's index will be one"
View
@@ -125,7 +125,8 @@ def rename_session(self, new_name):
def new_window(self,
window_name=None,
start_directory=None,
- attach=True):
+ attach=True,
+ window_index=''):
"""Return :class:`Window` from ``$ tmux new-window``.
.. note::
@@ -175,7 +176,8 @@ def new_window(self,
window_args += ('-n%s' % window_name,)
window_args += (
- '-t%s' % self.get('session_id'),
+ # empty string for window_index will use the first one available
+ '-t%s:%s' % (self.get('session_id'), window_index),
)
proc = self.tmux('new-window', *window_args)
@@ -462,3 +462,39 @@ def test_pane_order(self):
time.sleep(.2)
self.assertEqual(p.get('pane_current_path'), pane_path)
+
+
+class WindowIndexTest(TmuxTestCase):
+ yaml_config = """
+ session_name: sampleconfig
+ windows:
+ - window_name: zero
+ panes:
+ - echo 'zero'
+ - window_name: five
+ panes:
+ - echo 'five'
+ window_index: 5
+ - window_name: one
+ panes:
+ - echo 'one'
+ """
+
+ def test_window_index(self):
+ name_index_map = {
+ 'zero': '0',
+ 'one': '1',
+ 'five': '5',
+ }
+
+ sconfig = kaptan.Kaptan(handler='yaml')
+ sconfig = sconfig.import_config(self.yaml_config).get()
+ sconfig = config.expand(sconfig)
+ sconfig = config.trickle(sconfig)
+
+ builder = WorkspaceBuilder(sconf=sconfig)
+
+
+ for window, wconf in builder.iter_create_windows(self.session):
+ expected_index = name_index_map[window['window_name']]
+ self.assertEqual(window['window_index'], expected_index)
@@ -184,7 +184,8 @@ def iter_create_windows(self, s):
window_name=window_name,
start_directory=wconf[
'start_directory'] if 'start_directory' in wconf else None,
- attach=False # do not move to the new window
+ attach=False, # do not move to the new window
+ window_index=wconf.get('window_index', ''),
)
if i == int(1) and w1: # if first window, use window 1

0 comments on commit 94d12c5

Please sign in to comment.