creating new panes

66 views
Skip to first unread message

Richard Mitchell

unread,
Aug 14, 2019, 8:58:38 AM8/14/19
to iterm2-discuss
Is there an option, when splitting a pane, to only split the current pane evenly instead of resizing the other panes?

For example, lets say I have a window split into 3 panes, with the widths being: 20, 20, 200
I would like to create a new pane, such that I now have 20, 20, 100, 100
Instead the first two panes also get resized.

I can see where if one is creating panes from a  fresh window, having it auto resize each pane to go from 100 to 50,50 then 33,33,33 and finally 25,25,25,25 makes  a lot of sense.  However if the previous panes were already carefully sized, having them autoresize is not a feature.

(all the numbers above are just for demonstration purposes and by no means represent real screen sizes)

George Nachman

unread,
Aug 16, 2019, 2:44:03 AM8/16/19
to iterm2-...@googlegroups.com
I'm afraid there's no option for that. But it's easy to write a Python script that does this using the new API. Drop this in ~/Library/Application Support/iTerm2/Scripts and you can run it from the Scripts menu. If you want to get fancy, it's not hard to modify it so you can bind it to a keystroke.

#!/usr/bin/env python3.7

import iterm2
import math

def get(size, vertical):
  if vertical:
    return size.width
  return size.height

def set(size, value, vertical):
  if vertical:
    size.width = value
  else:
    size.height = value

async def async_gentle_split(connection, vertical):
  app = await iterm2.async_get_app(connection)
  tab = app.current_terminal_window.current_tab

  desired = {}
  for session in tab.sessions:
    desired[session.session_id] = session.grid_size

  orig_session = tab.current_session
  original_size = get(orig_session.grid_size, vertical)
  new_session = await orig_session.async_split_pane(vertical=vertical)

  await app.async_refresh(connection)
  tab = app.current_terminal_window.current_tab

  updated_orig_size = orig_session.grid_size
  set(updated_orig_size, math.floor(original_size / 2.0), vertical)
  desired[orig_session.session_id] = updated_orig_size

  updated_new_size = new_session.grid_size
  set(updated_new_size, math.ceil(original_size / 2.0), vertical)
  desired[new_session.session_id] = updated_new_size

  for session in tab.sessions:
    session.preferred_size = desired[session.session_id]

  await tab.async_update_layout()

async def main(connection):
  await async_gentle_split(connection, False)

iterm2.run_until_complete(main)

--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/iterm2-discuss/e01347a8-c1ed-4934-b2a0-e91d546d6a5e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages