Skip to content

Commit d37f62b

Browse files
committed
run hooks regardless of detached mode
1 parent 89b8d6c commit d37f62b

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

tmuxp/cli.py

+38-38
Original file line numberDiff line numberDiff line change
@@ -277,48 +277,48 @@ def reattach(session):
277277
else:
278278
sys.exit('Session created in detached state.')
279279

280-
if not detached:
281-
282-
if has_gte_version('2.6'):
283-
# tmuxp issue: https://github.com/tony/tmuxp/issues/309
284-
# tmux issue: https://github.com/tmux/tmux/issues/1106
285-
#
286-
# tmux now requires that the window be viewed with the client
287-
# before select-layout adjustments can be meaningful
288-
#
289-
# To handle this, let's create a temporary hook for this
290-
# session to iterage and run select-layout on all windows
291-
# after client attaches.
292-
cmd = [
293-
'set-hook',
294-
'-t', builder.session.id,
295-
'client-attached'
296-
]
297-
hook_cmd = []
298-
for window in builder.session.windows:
299-
# unfortunately, select-layout won't work unless
300-
# we've literally selected the window at least once
301-
# with the client
302-
hook_cmd.append('selectw -t {}'.format(window.id))
303-
# edit: removed -t, or else it won't respect main-pane-w/h
304-
hook_cmd.append('selectl'.format(window.id))
305-
hook_cmd.append('selectw -p'.format(window.id))
306-
307-
# unset the hook immediately after executing
308-
hook_cmd.append(
309-
'set-hook -u -t {target_session} client-attached'.format(
310-
target_session=builder.session.id
311-
)
280+
if has_gte_version('2.6'):
281+
# tmuxp issue: https://github.com/tony/tmuxp/issues/309
282+
# tmux issue: https://github.com/tmux/tmux/issues/1106
283+
#
284+
# tmux now requires that the window be viewed with the client
285+
# before select-layout adjustments can be meaningful
286+
#
287+
# To handle this, let's create a temporary hook for this
288+
# session to iterage and run select-layout on all windows
289+
# after client attaches.
290+
cmd = [
291+
'set-hook',
292+
'-t', builder.session.id,
293+
'client-attached'
294+
]
295+
hook_cmd = []
296+
for window in builder.session.windows:
297+
# unfortunately, select-layout won't work unless
298+
# we've literally selected the window at least once
299+
# with the client
300+
hook_cmd.append('selectw -t {}'.format(window.id))
301+
# edit: removed -t, or else it won't respect main-pane-w/h
302+
hook_cmd.append('selectl'.format(window.id))
303+
hook_cmd.append('selectw -p'.format(window.id))
304+
305+
# unset the hook immediately after executing
306+
hook_cmd.append(
307+
'set-hook -u -t {target_session} client-attached'.format(
308+
target_session=builder.session.id
312309
)
310+
)
311+
312+
# join the hook's commands with semicolons
313+
hook_cmd = '{}'.format('; '.join(hook_cmd))
313314

314-
# join the hook's commands with semicolons
315-
hook_cmd = '{}'.format('; '.join(hook_cmd))
315+
# append the hook command
316+
cmd.append(hook_cmd)
316317

317-
# append the hook command
318-
cmd.append(hook_cmd)
318+
# create the hook
319+
builder.session.cmd(*cmd)
319320

320-
# create the hook
321-
builder.session.cmd(*cmd)
321+
if not detached:
322322
builder.session.attach_session()
323323

324324
except exc.TmuxpException as e:

0 commit comments

Comments
 (0)