Windows

class libtmux.Window(session=None, **kwargs)

Bases: libtmux.common.TmuxMappingObject, libtmux.common.TmuxRelationalObject

tmux(1) window.

child_id_attribute = u'pane_id'

unique child ID key for TmuxRelationalObject

formatter_prefix = u'window_'

namespace used TmuxMappingObject

cmd(cmd, *args, **kwargs)

Return Server.cmd() defaulting target_window as target.

Send command to tmux with window_id as target-window.

Specifying ('-t', 'custom-target') or ('-tcustom_target') in args will override using the object’s window_id as target.

Return type:Server.cmd

Changed in version 0.8: Renamed from .tmux to .cmd.

select_layout(layout=None)

Wrapper for $ tmux select-layout <layout>.

even-horizontal: Panes are spread out evenly from left to right across the window.

even-vertical: Panes are spread evenly from top to bottom.

main-horizontal: A large (main) pane is shown at the top of the window and the remaining panes are spread from left to right in the leftover space at the bottom.

main-vertical: Similar to main-horizontal but the large pane is placed on the left and the others spread from top to bottom along the right.

tiled: Panes are spread out as evenly as possible over the window in both rows and columns.

custom: custom dimensions (see tmux(1) manpages).

Parameters:layout (str) – string of the layout, ‘even-horizontal’, ‘tiled’, etc.
set_window_option(option, value)

Wrapper for $ tmux set-window-option <option> <value>.

Parameters:
  • option (str) – option to set, e.g. ‘aggressive-resize’
  • value (bool) – window value. True/False will turn in ‘on’ and ‘off’, also accepts string of ‘on’ or ‘off’ directly.
Raises:

exc.OptionError, exc.UnknownOption, exc.InvalidOption, exc.AmbiguousOption

show_window_options(option=None, g=False)

Return a dict of options for the window.

For familiarity with tmux, the option option param forwards to pick a single option, forwarding to Window.show_window_option().

Parameters:
  • option (str) – optional. show a single option.
  • g (bool) – Pass -g flag for global variable
Return type:

dict

show_window_option(option, g=False)

Return a list of options for the window.

todo: test and return True/False for on/off string

Parameters:
  • option (str) – option to return.
  • g (bool) – Pass -g flag, global.
Return type:

str, int

Raises:

exc.OptionError, exc.UnknownOption, exc.InvalidOption, exc.AmbiguousOption

rename_window(new_name)

Return Window object $ tmux rename-window <new_name>.

Parameters:new_name (str) – name of the window
kill_window()

Kill the current Window object. $ tmux kill-window.

move_window(destination=u'', session=None)

Move the current Window object $ tmux move-window.

Parameters:
  • destination (str) – the target window or index to move the window to, default: empty string
  • session (str) – the target session or index to move the window to, default: current session.
select_window()

Select window. Return self.

To select a window object asynchrously. If a window object exists and is no longer longer the current window, w.select_window() will make w the current window.

Return type:Window
select_pane(target_pane)

Return selected Pane through $ tmux select-pane.

Parameters:target_pane (str) – target_pane, or -U,``-D``, -L, -R or -l.
Return type:Pane
last_pane()

Return last pane.

split_window(target=None, start_directory=None, attach=True, vertical=True)

Split window and return the created Pane.

Note

tmux(1) will move window to the new pane if the split-window target is off screen. tmux handles the -d the same way as new-window and attach in Session.new_window.

By default, this will make the window the pane is created in active. To remain on the same window and split the pane in another target window, pass in attach=False.

Used for splitting window and holding in a python object.

Parameters:
  • attach (bool) – make new window the current window after creating it, default True.
  • start_directory (str) – specifies the working directory in which the new window is created.
  • target (bool) – target_pane to split.
  • vertical (bool) – split vertically
Return type:

Pane

attached_pane

Return the attached Pane.

Return type:Pane
_panes

Property / alias to return _list_panes().

list_panes()

Return list of Pane for the window.

Return type:list of Pane
panes

Property / alias to return list_panes().

children

Alias panes for TmuxRelationalObject

clear() → None. Remove all items from D.
find_where(attrs)

Return object on first match.

Changed in version 0.4: Renamed from .findWhere to .find_where.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
get_by_id(id)

Return object based on child_id_attribute.

Based on .get() from backbone.js.

Parameters:id (str) –
Return type:object
items() → list of D's (key, value) pairs, as 2-tuples
iteritems() → an iterator over the (key, value) items of D
iterkeys() → an iterator over the keys of D
itervalues() → an iterator over the values of D
keys()

Return list of keys.

pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → list of D's values
where(attrs, first=False)

Return objects matching child objects properties.

Parameters:attrs (dict) – tmux properties to match
Return type:list