Skip to content

Commit

Permalink
Merge pull request #31 from stratoukos/master
Browse files Browse the repository at this point in the history
add window_index option
  • Loading branch information
tony committed Dec 5, 2013
2 parents 630bb09 + 2ee6007 commit 95d6df9
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
20 changes: 19 additions & 1 deletion doc/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------

Expand Down
24 changes: 24 additions & 0 deletions examples/window-index.json
Original file line number Diff line number Diff line change
@@ -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"
}
12 changes: 12 additions & 0 deletions examples/window-index.yaml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 4 additions & 2 deletions tmuxp/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions tmuxp/testsuite/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,40 @@ 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):
proc = self.session.tmux('show-option', '-gv', 'base-index')
base_index = int(proc.stdout[0])
name_index_map = {
'zero': 0 + base_index,
'one': 1 + base_index,
'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(int(window['window_index']), expected_index)
3 changes: 2 additions & 1 deletion tmuxp/workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95d6df9

Please sign in to comment.