Utilities#
Helper methods and mixins.
libtmux.common#
- libtmux.common.TMUX_MIN_VERSION = '1.8'#
Minimum version of tmux required to run libtmux
- libtmux.common.TMUX_MAX_VERSION = '3.3'#
Most recent version of tmux supported
- class libtmux.common.EnvironmentMixin(add_option=None)[source]#
Mixin class for managing session and server level environment variables in tmux.
- show_environment()[source]#
Show environment
$ tmux show-environment -t [session].Return dict of environment variables for the session.
Changed in version 0.13: Removed per-item lookups. Use
libtmux.common.EnvironmentMixin.getenv().
- class libtmux.common.tmux_cmd(*args, **kwargs)[source]#
tmux(1) command via
subprocess.Examples
proc = tmux_cmd('new-session', '-s%' % 'my session') if proc.stderr: raise exc.LibTmuxException( 'Command: %s returned error: %s' % (proc.cmd, proc.stderr) ) print('tmux command returned %s' % proc.stdout)
Equivalent to:
$ tmux new-session -s my session
Notes
Changed in version 0.8: Renamed from
tmuxtotmux_cmd.
- libtmux.common.get_version()[source]#
Return tmux version.
If tmux is built from git master, the version returned will be the latest version appended with -master, e.g.
2.4-master.If using OpenBSDβs base system tmux, the version will have
-openbsdappended to the latest version, e.g.2.4-openbsd.- Returns:
tmux version according to
shtuil.which()βs tmux- Return type:
distutils.version.LooseVersion- Return type:
LegacyVersion
- libtmux.common.has_gt_version(min_version)[source]#
Return affirmative if tmux version greater than minimum.
- libtmux.common.has_gte_version(min_version)[source]#
Return True if tmux version greater or equal to minimum.
- libtmux.common.has_lte_version(max_version)[source]#
Return True if tmux version less or equal to minimum.
- libtmux.common.has_minimum_version(raises=True)[source]#
Return if tmux meets version requirement. Version >1.8 or above.
- Parameters:
raises (bool) β raise exception if below minimum version requirement
- Returns:
True if tmux meets minimum required version.
- Return type:
- Raises:
libtmux.exc.VersionTooLow β tmux version below minimum required for libtmux
Notes
Changed in version 0.7.0: No longer returns version, returns True or False
Changed in version 0.1.7: Versions will now remove trailing letters per `Issue 55`_.
- Return type:
- libtmux.common.session_check_name(session_name)[source]#
Raises exception session name invalid, modeled after tmux function.
tmux(1) session names may not be empty, or include periods or colons. These delimiters are reserved for noting session, window and pane.
- Parameters:
session_name (str) β Name of session.
- Raises:
exc.BadSessionName β Invalid session name.
- Return type:
- libtmux.common.handle_option_error(error)[source]#
Raises exception if error in option command found.
In tmux 3.0, show-option and show-window-otion return invalid option instead of unknown option. See https://github.com/tmux/tmux/blob/3.0/cmd-show-options.c.
In tmux >2.4, there are 3 different types of option errors:
unknown option
invalid option
ambiguous option
In tmux <2.4, unknown option was the only option.
All errors raised will have the base error of
exc.OptionError. So to catch any option error, useexcept exc.OptionError.- Parameters:
error (str) β Error response from subprocess call.
- Raises:
exc.OptionError β
- Return type: