Skip to content

Commit 55e0d5b

Browse files
committed
midway commit: pane_start_path / start_directory support
1 parent 74f1be4 commit 55e0d5b

File tree

6 files changed

+70
-23
lines changed

6 files changed

+70
-23
lines changed

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Here you can find the recent changes to tmuxp.
1313
- [cli] ``tmuxp freeze <filename>`` experimental
1414
- [freeze] [tests] tmuxp now has experimental support for freezing live
1515
sessions.
16-
- [internals] :meth:`Window.kill_window()`
16+
- [internal] :meth:`Window.kill_window()`
17+
- [internal] support for ``start_directory`` (work in progress)
1718

1819
2013-10-29
1920
----------

tmuxp/session.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ def switch_client(self, target_session=None):
100100
if proc.stderr:
101101
raise Exception(proc.stderr)
102102

103-
104103
def rename_session(self, new_name):
105104
'''rename session and return new :class:`Session` object
106105
@@ -121,6 +120,7 @@ def rename_session(self, new_name):
121120

122121
def new_window(self,
123122
window_name=None,
123+
start_directory=None,
124124
attach=True):
125125
'''
126126
``$ tmux new-window``
@@ -134,10 +134,12 @@ def new_window(self,
134134
135135
.. code-block:: bash
136136
137-
$ tmux new-window -n <window_name>
137+
$ tmux new-window -n <window_name> -c <start_directory>
138138
139139
:type window_name: string
140-
140+
:param start_directory: specifies the working directory in which the
141+
new created.
142+
:type start_directory: string
141143
:param attach: make new window the current window after creating it,
142144
default True.
143145
:param type: bool
@@ -149,14 +151,22 @@ def new_window(self,
149151
window_args = (
150152
'-t%s' % self.get('session_id'),
151153
'-P',
152-
'-F%s' % '\t'.join(tmux_formats), # output
153154
)
154155

156+
if not attach:
157+
window_args += ('-d',)
158+
159+
if start_directory:
160+
# start_directory = pipes.quote(start_directory)
161+
logger.error(start_directory)
162+
window_args += ('-c %s' % start_directory,)
163+
155164
if window_name:
156165
window_args += ('-n%s' % window_name,)
157166

158-
if not attach:
159-
window_args += ('-d',)
167+
window_args += (
168+
'-F%s' % '\t'.join(tmux_formats), # output
169+
)
160170

161171
proc = self.tmux('new-window', *window_args)
162172

tmuxp/testsuite/test_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class ExpandTest(unittest.TestCase):
158158
]
159159
},
160160
{
161+
'start_directory': '/var/log',
161162
'options': {'automatic_rename': True, },
162163
'panes': [
163164
{'shell_command': 'htop'},
@@ -195,6 +196,7 @@ class ExpandTest(unittest.TestCase):
195196
]
196197
},
197198
{
199+
'start_directory': '/var/log',
198200
'options': {'automatic_rename': True},
199201
'panes': [
200202
{'shell_command': ['htop']},

tmuxp/testsuite/test_workspacebuilder.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ class TwoPaneTest(TmuxTestCase):
2626
panes:
2727
- shell_command:
2828
- vim
29-
start_directory: '~'
3029
- shell_command:
3130
- echo "hey"
3231
window_name: editor
3332
- panes:
3433
- shell_command:
3534
- tail -F /var/log/syslog
36-
start_directory: /var/log
3735
window_name: logging
3836
- window_name: test
3937
panes:
@@ -72,7 +70,6 @@ class ThreePaneTest(TmuxTestCase):
7270
panes:
7371
- shell_command:
7472
- vim
75-
start_directory: '~'
7673
- shell_command:
7774
- echo "hey"
7875
- shell_command:
@@ -114,7 +111,6 @@ class FocusAndPaneIndexTest(TmuxTestCase):
114111
panes:
115112
- shell_command:
116113
- vim
117-
start_directory: '~'
118114
- shell_command:
119115
- echo "hey"
120116
- shell_command:
@@ -125,8 +121,7 @@ class FocusAndPaneIndexTest(TmuxTestCase):
125121
panes:
126122
- shell_command:
127123
- vim
128-
start_directory: '~'
129-
focus: true
124+
rocus: true
130125
- shell_command:
131126
- echo "hey"
132127
- shell_command:
@@ -273,5 +268,40 @@ def test_automatic_rename_option(self):
273268
self.assertNotEqual(w.get('window_name'), 'man')
274269

275270

271+
class StartDirectoryTest(TmuxTestCase):
272+
273+
yaml_config = '''
274+
session_name: sampleconfig
275+
start_directory: '~'
276+
windows:
277+
- window_name: test
278+
start_directory: /var/log
279+
layout: main-horizontal
280+
panes:
281+
- shell_command:
282+
- vim
283+
- shell_command:
284+
- echo "hey"
285+
- shell_command:
286+
- echo "moo"
287+
'''
288+
289+
def test_start_directory(self):
290+
sconfig = kaptan.Kaptan(handler='yaml')
291+
sconfig = sconfig.import_config(self.yaml_config).get()
292+
#sconfig = config.expand(sconfig)
293+
294+
builder = WorkspaceBuilder(sconf=sconfig)
295+
builder.build(session=self.session)
296+
297+
assert(self.session == builder.session)
298+
logger.error(self.session)
299+
self.assertEqual(1, len(self.session.windows))
300+
for window in self.session.windows:
301+
for p in window.panes:
302+
logger.error(dict(p))
303+
logger.error(p.get('pane_start_path'))
304+
self.assertEqual('/var/log', p.get('pane_start_path'))
305+
276306
if __name__ == '__main__':
277307
unittest.main()

tmuxp/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def __init__(self, *args, **kwargs):
6969
self.stderr = stderr.decode().split('\n')
7070
self.stderr = list(filter(None, self.stderr)) # filter empty values
7171

72+
if 'new-window' in cmd:
73+
logger.error(' '.join(cmd))
74+
7275
if 'has-session' in cmd and len(self.stderr):
7376
if not self.stdout:
7477
self.stdout = self.stderr[0]

tmuxp/workspacebuilder.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,19 @@ def iter_create_windows(self, s):
161161
else:
162162
window_name = wconf['window_name']
163163

164+
w1 = None
164165
if i == int(1): # if first window, use window 1
165-
# w = s.select_window(1)
166-
w = s.attached_window()
167-
w = w.rename_window(window_name)
168-
else:
169-
w = s.new_window(
170-
window_name=window_name,
171-
attach=False # do not move to the new window
172-
)
173-
166+
w1 = s.attached_window()
167+
w = s.new_window(
168+
window_name=window_name,
169+
start_directory=wconf['start_directory'] if 'start_directory' in wconf else None,
170+
attach=False # do not move to the new window
171+
)
172+
173+
if i == int(1) and w1: # if first window, use window 1
174+
w1.kill_window()
174175
assert(isinstance(w, Window))
175-
176+
s.server._update_windows()
176177
if 'options' in wconf and isinstance(wconf['options'], dict):
177178
for key, val in wconf['options'].items():
178179
w.set_window_option(key, val)

0 commit comments

Comments
 (0)