Refactor some calls to run_tmux_command into a new function
This commit is contained in:
parent
1348472f1e
commit
5146978870
|
@ -10,7 +10,7 @@ from powerline.lib.config import ConfigLoader
|
||||||
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config
|
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config
|
||||||
from powerline.tmux import TmuxPowerline
|
from powerline.tmux import TmuxPowerline
|
||||||
from powerline.lib.shell import which
|
from powerline.lib.shell import which
|
||||||
from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, get_tmux_version
|
from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, set_tmux_environment, get_tmux_version
|
||||||
from powerline.lib.encoding import get_preferred_output_encoding
|
from powerline.lib.encoding import get_preferred_output_encoding
|
||||||
from powerline.renderers.tmux import attr_to_tmux_attr
|
from powerline.renderers.tmux import attr_to_tmux_attr
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ def source_tmux_files(pl, args):
|
||||||
if not os.environ.get('POWERLINE_COMMAND'):
|
if not os.environ.get('POWERLINE_COMMAND'):
|
||||||
cmd = deduce_command()
|
cmd = deduce_command()
|
||||||
if cmd:
|
if cmd:
|
||||||
run_tmux_command('set-environment', '-g', 'POWERLINE_COMMAND', deduce_command())
|
set_tmux_environment('POWERLINE_COMMAND', deduce_command(), remove=False)
|
||||||
run_tmux_command('refresh-client')
|
run_tmux_command('refresh-client')
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,8 +103,7 @@ def init_environment(pl, args):
|
||||||
('_POWERLINE_SESSION_COLOR', 'session'),
|
('_POWERLINE_SESSION_COLOR', 'session'),
|
||||||
):
|
):
|
||||||
highlight = get_highlighting(highlight_group)
|
highlight = get_highlighting(highlight_group)
|
||||||
run_tmux_command('set-environment', '-g', varname, powerline.renderer.hlstyle(**highlight)[2:-1])
|
set_tmux_environment(varname, powerline.renderer.hlstyle(**highlight)[2:-1])
|
||||||
run_tmux_command('set-environment', '-r', varname)
|
|
||||||
for varname, prev_group, next_group in (
|
for varname, prev_group, next_group in (
|
||||||
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'),
|
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'),
|
||||||
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'),
|
('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'),
|
||||||
|
@ -112,15 +111,14 @@ def init_environment(pl, args):
|
||||||
):
|
):
|
||||||
prev_highlight = get_highlighting(prev_group)
|
prev_highlight = get_highlighting(prev_group)
|
||||||
next_highlight = get_highlighting(next_group)
|
next_highlight = get_highlighting(next_group)
|
||||||
run_tmux_command(
|
set_tmux_environment(
|
||||||
'set-environment', '-g', varname,
|
varname,
|
||||||
powerline.renderer.hlstyle(
|
powerline.renderer.hlstyle(
|
||||||
fg=prev_highlight['bg'],
|
fg=prev_highlight['bg'],
|
||||||
bg=next_highlight['bg'],
|
bg=next_highlight['bg'],
|
||||||
attr=0,
|
attr=0,
|
||||||
)[2:-1]
|
)[2:-1]
|
||||||
)
|
)
|
||||||
run_tmux_command('set-environment', '-r', varname)
|
|
||||||
for varname, attr, group in (
|
for varname, attr, group in (
|
||||||
('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'),
|
('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'),
|
||||||
('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'),
|
('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'),
|
||||||
|
@ -139,21 +137,10 @@ def init_environment(pl, args):
|
||||||
):
|
):
|
||||||
if attr == 'attr':
|
if attr == 'attr':
|
||||||
attrs = attr_to_tmux_attr(get_highlighting(group)[attr])
|
attrs = attr_to_tmux_attr(get_highlighting(group)[attr])
|
||||||
run_tmux_command(
|
set_tmux_environment(varname, ']#['.join(attrs))
|
||||||
'set-environment', '-g', varname,
|
set_tmux_environment(varname + '_LEGACY', ','.join(attrs))
|
||||||
']#['.join(attrs)
|
|
||||||
)
|
|
||||||
run_tmux_command(
|
|
||||||
'set-environment', '-g', varname + '_LEGACY',
|
|
||||||
','.join(attrs)
|
|
||||||
)
|
|
||||||
run_tmux_command('set-environment', '-r', varname + '_LEGACY')
|
|
||||||
else:
|
else:
|
||||||
run_tmux_command(
|
set_tmux_environment(varname, 'colour' + str(get_highlighting(group)[attr][0]))
|
||||||
'set-environment', '-g', varname,
|
|
||||||
'colour' + str(get_highlighting(group)[attr][0])
|
|
||||||
)
|
|
||||||
run_tmux_command('set-environment', '-r', varname)
|
|
||||||
|
|
||||||
|
|
||||||
def get_main_config(args):
|
def get_main_config(args):
|
||||||
|
|
|
@ -37,6 +37,22 @@ def get_tmux_output(pl, *args):
|
||||||
return _run_tmux(lambda cmd: run_cmd(pl, cmd), args)
|
return _run_tmux(lambda cmd: run_cmd(pl, cmd), args)
|
||||||
|
|
||||||
|
|
||||||
|
def set_tmux_environment(varname, value, remove=True):
|
||||||
|
'''Set tmux global environment variable
|
||||||
|
|
||||||
|
:param str varname:
|
||||||
|
Name of the variable to set.
|
||||||
|
:param str value:
|
||||||
|
Variable value.
|
||||||
|
:param bool remove:
|
||||||
|
True if variable should be removed from the environment prior to
|
||||||
|
attaching any client (runs ``tmux set-environment -r {varname}``).
|
||||||
|
'''
|
||||||
|
run_tmux_command('set-environment', '-g', varname, value)
|
||||||
|
if remove:
|
||||||
|
run_tmux_command('set-environment', '-r', varname)
|
||||||
|
|
||||||
|
|
||||||
NON_DIGITS = re.compile('[^0-9]+')
|
NON_DIGITS = re.compile('[^0-9]+')
|
||||||
DIGITS = re.compile('[0-9]+')
|
DIGITS = re.compile('[0-9]+')
|
||||||
NON_LETTERS = re.compile('[^a-z]+')
|
NON_LETTERS = re.compile('[^a-z]+')
|
||||||
|
|
Loading…
Reference in New Issue