|
14 | 14 | import click
|
15 | 15 | import kaptan
|
16 | 16 | from click.exceptions import FileError
|
17 |
| -from libtmux.common import has_minimum_version, which |
| 17 | +from libtmux.common import has_minimum_version, which, has_gte_version |
18 | 18 | from libtmux.exc import TmuxCommandNotFound
|
19 | 19 | from libtmux.server import Server
|
20 | 20 |
|
@@ -278,7 +278,49 @@ def reattach(session):
|
278 | 278 | sys.exit('Session created in detached state.')
|
279 | 279 |
|
280 | 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 | + ) |
| 312 | + ) |
| 313 | + |
| 314 | + # join the hook's commands with semicolons |
| 315 | + hook_cmd = '{}'.format('; '.join(hook_cmd)) |
| 316 | + |
| 317 | + # append the hook command |
| 318 | + cmd.append(hook_cmd) |
| 319 | + |
| 320 | + # create the hook |
| 321 | + builder.session.cmd(*cmd) |
281 | 322 | builder.session.attach_session()
|
| 323 | + |
282 | 324 | except exc.TmuxpException as e:
|
283 | 325 | import traceback
|
284 | 326 |
|
|
0 commit comments