Move some functions to from bindings.config to bindings.tmux

This commit is contained in:
ZyX 2014-08-22 23:47:13 +04:00
parent 88515ab472
commit eee150f97c
2 changed files with 55 additions and 45 deletions

View File

@ -2,58 +2,15 @@
from __future__ import absolute_import, unicode_literals, print_function
from collections import namedtuple
import os
import subprocess
import re
import sys
from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY
from powerline.lib.config import ConfigLoader
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config
from powerline.lib.shell import run_cmd, which
TmuxVersionInfo = namedtuple('TmuxVersionInfo', ('major', 'minor', 'suffix'))
def get_tmux_executable_name():
'''Returns tmux executable name
It should be defined in POWERLINE_TMUX_EXE environment variable, otherwise
it is simply tmux.
'''
return os.environ.get('POWERLINE_TMUX_EXE', 'tmux')
def _run_tmux(runner, args):
return runner([get_tmux_executable_name()] + list(args))
def run_tmux_command(*args):
'''Run tmux command, ignoring the output'''
_run_tmux(subprocess.check_call, args)
def get_tmux_output(pl, *args):
'''Run tmux command and return its output'''
return _run_tmux(lambda cmd: run_cmd(pl, cmd), args)
NON_DIGITS = re.compile('[^0-9]+')
DIGITS = re.compile('[0-9]+')
NON_LETTERS = re.compile('[^a-z]+')
def get_tmux_version(pl):
version_string = get_tmux_output(pl, '-V')
_, version_string = version_string.split(' ')
version_string = version_string.strip()
major, minor = version_string.split('.')
suffix = DIGITS.subn('', minor)[0] or None
minor = NON_DIGITS.subn('', minor)[0]
return TmuxVersionInfo(int(major), int(minor), suffix)
from powerline.lib.shell import which
from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, get_tmux_version
CONFIG_FILE_NAME = re.compile(r'powerline_tmux_(?P<major>\d+)\.(?P<minor>\d+)(?P<suffix>[a-z]+)?(?:_(?P<mod>plus|minus))?\.conf')

View File

@ -0,0 +1,53 @@
# vim:fileencoding=utf-8:noet
from __future__ import absolute_import, unicode_literals, division, print_function
import re
import os
import subprocess
from collections import namedtuple
from powerline.lib.shell import run_cmd
TmuxVersionInfo = namedtuple('TmuxVersionInfo', ('major', 'minor', 'suffix'))
def get_tmux_executable_name():
'''Returns tmux executable name
It should be defined in POWERLINE_TMUX_EXE environment variable, otherwise
it is simply tmux.
'''
return os.environ.get('POWERLINE_TMUX_EXE', 'tmux')
def _run_tmux(runner, args):
return runner([get_tmux_executable_name()] + list(args))
def run_tmux_command(*args):
'''Run tmux command, ignoring the output'''
_run_tmux(subprocess.check_call, args)
def get_tmux_output(pl, *args):
'''Run tmux command and return its output'''
return _run_tmux(lambda cmd: run_cmd(pl, cmd), args)
NON_DIGITS = re.compile('[^0-9]+')
DIGITS = re.compile('[0-9]+')
NON_LETTERS = re.compile('[^a-z]+')
def get_tmux_version(pl):
version_string = get_tmux_output(pl, '-V')
_, version_string = version_string.split(' ')
version_string = version_string.strip()
major, minor = version_string.split('.')
suffix = DIGITS.subn('', minor)[0] or None
minor = NON_DIGITS.subn('', minor)[0]
return TmuxVersionInfo(int(major), int(minor), suffix)