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
-
Description
Names, titles, start directories and file paths passed to libtmux as plain
strare kept as typed. Wrap a format your program wrote inFormatto have tmux expand it, as it does for#{...}intmux.conf. Where tmux always expands an argument, such asdisplay_message(), aFormatis 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
+orjoin(), which keep it literal; place it inside an expression, such as a conditional or comparison, withescape(). 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"TrueA plain
stris 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
Other members6
- template: str attribute
- __add__ method Append other; a
stris escaped and stays literal. - __bool__ method Return whether the format is non-empty, as for
str. - __radd__ method Prepend other; a
stris escaped and stays literal. - __repr__ method Show the format as it would be written.
- __str__ method Return the format as tmux receives it.