Skip to content

Commit 801a282

Browse files
committed
Try set-option default-path before creation if -c entered. Add util.check_version. Expecting 1.9 to fail on this. wip
1 parent 55e0d5b commit 801a282

File tree

5 files changed

+54
-28
lines changed

5 files changed

+54
-28
lines changed

tmuxp/server.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,7 @@ def __list_sessions(self):
8585
)
8686

8787
if proc.stderr:
88-
if 'unknown option -- F' in proc.stderr[0]:
89-
proc = self.tmux(
90-
'list-sessions',
91-
)
92-
93-
if proc.stderr:
94-
raise Exception(proc.stderr)
95-
else:
96-
return 'hi'
97-
else:
98-
raise Exception(proc.stderr)
88+
raise Exception(proc.stderr)
9989
else:
10090
session_info = proc.stdout[0]
10191

tmuxp/session.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,24 +148,32 @@ def new_window(self,
148148
wformats = ['session_name', 'session_id'] + formats.WINDOW_FORMATS
149149
tmux_formats = ['#{%s}' % f for f in wformats]
150150

151-
window_args = (
152-
'-t%s' % self.get('session_id'),
153-
'-P',
154-
)
151+
window_args = tuple()
152+
155153

156154
if not attach:
157155
window_args += ('-d',)
158156

157+
window_args += (
158+
'-P',
159+
)
160+
159161
if start_directory:
160-
# start_directory = pipes.quote(start_directory)
162+
self.tmux('set-option', 'default-path', start_directory)
163+
self.server.tmux('set-option', 'default-path', start_directory)
164+
#start_directory = pipes.quote(start_directory)
161165
logger.error(start_directory)
162-
window_args += ('-c %s' % start_directory,)
166+
#window_args += ('-c%s' % start_directory,)
167+
163168

169+
window_args += (
170+
'-F"%s"' % '\t'.join(tmux_formats), # output
171+
)
164172
if window_name:
165173
window_args += ('-n%s' % window_name,)
166174

167175
window_args += (
168-
'-F%s' % '\t'.join(tmux_formats), # output
176+
'-t%s' % self.get('session_id'),
169177
)
170178

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

tmuxp/testsuite/test_workspacebuilder.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,34 @@ def test_automatic_rename_option(self):
269269

270270

271271
class StartDirectoryTest(TmuxTestCase):
272-
273272
yaml_config = '''
274273
session_name: sampleconfig
275-
start_directory: '~'
274+
#start_directory: '/home/tony'
276275
windows:
277276
- window_name: test
278-
start_directory: /var/log
277+
start_directory: '/var/log'
279278
layout: main-horizontal
279+
options:
280+
main-pane-height: 50
280281
panes:
281282
- shell_command:
282-
- vim
283+
- echo "hey"
284+
- shell_command:
285+
- echo "moo"
286+
- window_name: testsa
287+
start_directory: '/dev'
288+
layout: main-horizontal
289+
panes:
290+
- shell_command:
291+
- pwd
283292
- shell_command:
284293
- echo "hey"
285294
- shell_command:
286295
- echo "moo"
287296
'''
288297

289298
def test_start_directory(self):
299+
290300
sconfig = kaptan.Kaptan(handler='yaml')
291301
sconfig = sconfig.import_config(self.yaml_config).get()
292302
#sconfig = config.expand(sconfig)
@@ -296,12 +306,12 @@ def test_start_directory(self):
296306

297307
assert(self.session == builder.session)
298308
logger.error(self.session)
299-
self.assertEqual(1, len(self.session.windows))
309+
#self.assertEqual(1, len(self.session.windows))
300310
for window in self.session.windows:
301311
for p in window.panes:
302312
logger.error(dict(p))
303313
logger.error(p.get('pane_start_path'))
304-
self.assertEqual('/var/log', p.get('pane_start_path'))
314+
self.assertTrue(any(p.get('pane_start_path', ['/var/log', '/dev/'])))
305315

306316
if __name__ == '__main__':
307317
unittest.main()

tmuxp/util.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ def __init__(self, *args, **kwargs):
5353
self.process = subprocess.Popen(
5454
cmd,
5555
stdout=subprocess.PIPE,
56-
stderr=subprocess.PIPE
56+
stderr=subprocess.PIPE,
5757
)
5858
self.process.wait()
5959
stdout = self.process.stdout.read()
6060
stderr = self.process.stderr.read()
6161
except Exception as e:
6262
logger.error('Exception for %s: \n%s' % (
63-
cmd,
63+
subprocess.list2cmdline(cmd),
6464
e.message)
6565
)
6666
self.stdout = stdout.decode().split('\n')
@@ -221,8 +221,25 @@ def which(exe=None):
221221
logger.error('No executable was passed to be searched by which')
222222
return None
223223

224+
def get_version(version):
225+
""" Return True if tmux version installed.
226+
227+
:param version: version, '1.8'
228+
:param type: string
229+
"""
230+
proc = tmux('-V')
231+
232+
if proc.stderr:
233+
raise Exception(proc.stderr)
234+
235+
installed_version = proc.stdout[0].split('tmux ')[1]
236+
237+
return StrictVersion(installed_version) == StrictVersion(version)
224238

225239
def version():
240+
"""
241+
check to see if tmux is version >1.8 or above
242+
"""
226243
proc = tmux('-V')
227244

228245
if proc.stderr:

tmuxp/workspacebuilder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def iter_create_windows(self, s):
164164
w1 = None
165165
if i == int(1): # if first window, use window 1
166166
w1 = s.attached_window()
167+
w1.attached_pane().send_keys('la')
167168
w = s.new_window(
168169
window_name=window_name,
169170
start_directory=wconf['start_directory'] if 'start_directory' in wconf else None,
@@ -241,8 +242,8 @@ def freeze(session):
241242
pconf = {}
242243
pconf['shell_command'] = []
243244
if 'shell_command_before' not in wconf:
244-
pconf['shell_command'].append(
245-
'cd ' + p.get('pane_current_path'))
245+
pconf['shell_command'].append(
246+
'cd ' + p.get('pane_current_path'))
246247
pconf['shell_command'].append(p.get('pane_current_command'))
247248
wconf['panes'].append(pconf)
248249
# logger.error(p)

0 commit comments

Comments
 (0)