Make `powerline-config` also accept overrides from env variables

Ref #1201
This commit is contained in:
ZyX 2015-01-06 22:47:35 +03:00
parent 87ebe41f30
commit a47a486394
3 changed files with 28 additions and 18 deletions

View File

@ -8,11 +8,12 @@ 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.tmux import TmuxPowerline
from powerline.shell import ShellPowerline
from powerline.lib.shell import which
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.renderers.tmux import attrs_to_tmux_attrs
from powerline.commands.main import finish_args
CONFIG_FILE_NAME = re.compile(r'powerline_tmux_(?P<major>\d+)\.(?P<minor>\d+)(?P<suffix>[a-z]+)?(?:_(?P<mod>plus|minus))?\.conf')
@ -77,10 +78,19 @@ def source_tmux_files(pl, args):
run_tmux_command('refresh-client')
class EmptyArgs(object):
def __init__(self, ext, config_path):
self.ext = ext
self.config_path = None
def __getattr__(self, attr):
return None
def init_environment(pl, args):
'''Initialize tmux environment from tmux configuration
'''
powerline = TmuxPowerline(args.config_path)
powerline = ShellPowerline(finish_args(EmptyArgs('tmux', args.config_path)))
# TODO Move configuration files loading out of Powerline object and use it
# directly
powerline.update_renderer()

View File

@ -23,6 +23,21 @@ else:
def finish_args(environ, args):
'''Do some final transformations
Transforms ``*_override`` arguments into dictionaries, adding overrides from
environment variables. Transforms ``renderer_arg`` argument into dictionary
as well, but only if it is true.
:param dict environ:
Environment from which additional overrides should be taken from.
:param args:
Arguments object returned by
:py:meth:`argparse.ArgumentParser.parse_args`. Will be modified
in-place.
:return: Object received as second (``args``) argument.
'''
args.config_override = mergeargs(chain(
(parsedotval(v) for v in args.config_override or ()),
parse_override_var(environ.get('POWERLINE_CONFIG_OVERRIDES', '')),
@ -33,6 +48,7 @@ def finish_args(environ, args):
))
if args.renderer_arg:
args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True)
return args
def get_argparser(ArgumentParser=argparse.ArgumentParser):

View File

@ -1,16 +0,0 @@
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
from powerline import Powerline
class TmuxPowerline(Powerline):
def init(self, config_paths):
self.paths = config_paths
return super(TmuxPowerline, self).init('tmux')
def get_config_paths(self):
if self.paths:
return self.paths
else:
return super(TmuxPowerline, self).get_config_paths()