Core Library0.xAPI reference

Choose documentation 3

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

MoreLess about this notice

class libtmux

Format

A tmux format that tmux expands, instead of storing it as typed.

Source and package
Qualified name
libtmux.Format
Module
libtmux
Package
libtmux
Source
src/libtmux/formats.py
class libtmux.Format

Description

Names, titles, start directories and file paths passed to libtmux as plain str are kept as typed. Wrap a format your program wrote in Format to have tmux expand it, as it does for #{...} in tmux.conf. Where tmux always expands an argument, such as display_message(), a Format is accepted too, so text from users or files can be combined with it safely.

Only pass text your program wrote. Add text from users or files with + or join(), which keep it literal; place it inside an expression, such as a conditional or comparison, with escape(). Never place it inside #(...), which runs a shell command.

Examples

Open a pane in the directory of the session's active pane:

>>> pane.split(start_directory=Format("#{pane_current_path}"))
Pane(...)

Name a window after its session, with user text kept literal:

>>> user_text = "x#S"
>>> window.rename_window(Format("#{session_name}-") + user_text)
Window(...)
>>> window.window_name == f"{session.session_name}-x#S"
True

A plain str is never expanded:

>>> window.rename_window("#{session_name}")
Window(...)
>>> window.window_name
'#{session_name}'

Plain text cannot be added where tmux would read it as format syntax:

>>> Format("#{?pane_active,") + "yes"
Traceback (most recent call last):
...
ValueError: cannot add plain text to Format('#{?pane_active,'): ...

Members8 members

Common operations2

  • escape method Return a format that tmux expands back to text.
  • join method Join parts with this format between them, escaping each str.

Other members6

  • template: str attribute
  • __add__ method Append other; a str is escaped and stays literal.
  • __bool__ method Return whether the format is non-empty, as for str.
  • __radd__ method Prepend other; a str is escaped and stays literal.
  • __repr__ method Show the format as it would be written.
  • __str__ method Return the format as tmux receives it.
Esc
Search in

Type to search.

Reference previewOpen reference