parent
4bae6c6666
commit
45ccbee171
|
@ -43,7 +43,7 @@ Powerline script overrides
|
|||
Powerline script has a number of options controlling powerline behavior. Here
|
||||
``VALUE`` always means “some JSON object”.
|
||||
|
||||
``-c KEY.NESTED_KEY=VALUE`` or ``--config=KEY.NESTED_KEY=VALUE``
|
||||
``-c KEY.NESTED_KEY=VALUE`` or ``--config-override=KEY.NESTED_KEY=VALUE``
|
||||
Overrides options from :file:`powerline/config.json`.
|
||||
``KEY.KEY2.KEY3=VALUE`` is a shortcut for ``KEY={"KEY2": {"KEY3": VALUE}}``.
|
||||
Multiple options (i.e. ``-c K1=V1 -c K2=V2``) are allowed, result (in the
|
||||
|
@ -53,7 +53,7 @@ Powerline script has a number of options controlling powerline behavior. Here
|
|||
If ``VALUE`` is omitted then corresponding key will be removed from the
|
||||
configuration (if it was present).
|
||||
|
||||
``-t THEME_NAME.KEY.NESTED_KEY=VALUE`` or ``--theme-option=THEME_NAME.KEY.NESTED_KEY=VALUE``
|
||||
``-t THEME_NAME.KEY.NESTED_KEY=VALUE`` or ``--theme-override=THEME_NAME.KEY.NESTED_KEY=VALUE``
|
||||
Overrides options from :file:`powerline/themes/{ext}/{THEME_NAME}.json`.
|
||||
``KEY.NESTED_KEY=VALUE`` is processed like described above, ``{ext}`` is the
|
||||
first argument to powerline script. May be passed multiple times.
|
||||
|
|
|
@ -36,11 +36,11 @@ class Args(object):
|
|||
renderer_module = '.zsh'
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
def config_override(self):
|
||||
return get_var_config('POWERLINE_CONFIG_OVERRIDES')
|
||||
|
||||
@property
|
||||
def theme_option(self):
|
||||
def theme_override(self):
|
||||
return get_var_config('POWERLINE_THEME_CONFIG')
|
||||
|
||||
@property
|
||||
|
|
|
@ -21,12 +21,12 @@ else:
|
|||
|
||||
|
||||
def finish_args(args):
|
||||
if args.config:
|
||||
args.config = mergeargs((parsedotval(v) for v in args.config))
|
||||
if args.theme_option:
|
||||
args.theme_option = mergeargs((parsedotval(v) for v in args.theme_option))
|
||||
if args.config_override:
|
||||
args.config_override = mergeargs((parsedotval(v) for v in args.config_override))
|
||||
if args.theme_override:
|
||||
args.theme_override = mergeargs((parsedotval(v) for v in args.theme_override))
|
||||
else:
|
||||
args.theme_option = {}
|
||||
args.theme_override = {}
|
||||
if args.renderer_arg:
|
||||
args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg))
|
||||
|
||||
|
@ -43,8 +43,8 @@ def get_argparser(ArgumentParser=argparse.ArgumentParser):
|
|||
parser.add_argument('--last-exit-code', metavar='INT', type=int, help='Last exit code.')
|
||||
parser.add_argument('--last-pipe-status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()], help='Like above, but is supposed to contain space-separated array of statuses, representing exit statuses of commands in one pipe.')
|
||||
parser.add_argument('--jobnum', metavar='INT', type=int, help='Number of jobs.')
|
||||
parser.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', type=arg_to_unicode, action='append', help='Configuration overrides for `config.json\'. Is translated to a dictionary and merged with the dictionary obtained from actual JSON configuration: KEY.KEY=VALUE is translated to `{"KEY": {"KEY": VALUE}}\' and then merged recursively. VALUE may be any JSON value, values that are not `null\', `true\', `false\', start with digit, `{\', `[\' are treated like strings. If VALUE is omitted then corresponding key is removed.')
|
||||
parser.add_argument('-t', '--theme-option', metavar='THEME.KEY.KEY=VALUE', type=arg_to_unicode, action='append', help='Like above, but theme-specific. THEME should point to an existing and used theme to have any effect, but it is fine to use any theme here.')
|
||||
parser.add_argument('-c', '--config-override', metavar='KEY.KEY=VALUE', type=arg_to_unicode, action='append', help='Configuration overrides for `config.json\'. Is translated to a dictionary and merged with the dictionary obtained from actual JSON configuration: KEY.KEY=VALUE is translated to `{"KEY": {"KEY": VALUE}}\' and then merged recursively. VALUE may be any JSON value, values that are not `null\', `true\', `false\', start with digit, `{\', `[\' are treated like strings. If VALUE is omitted then corresponding key is removed.')
|
||||
parser.add_argument('-t', '--theme-override', metavar='THEME.KEY.KEY=VALUE', type=arg_to_unicode, action='append', help='Like above, but theme-specific. THEME should point to an existing and used theme to have any effect, but it is fine to use any theme here.')
|
||||
parser.add_argument('-R', '--renderer-arg', metavar='KEY=VAL', type=arg_to_unicode, action='append', help='Like above, but provides argument for renderer. Is supposed to be used only by shell bindings to provide various data like last-exit-code or last-pipe-status (they are not using `--renderer-arg\' for historical resons: `--renderer-arg\' was added later).')
|
||||
parser.add_argument('-p', '--config-path', action='append', metavar='PATH', help='Path to configuration directory. If it is present then configuration files will only be seeked in the provided path. May be provided multiple times to search in a list of directories.')
|
||||
parser.add_argument('--socket', metavar='ADDRESS', type=str, help='Socket address to use in daemon clients. Is always UNIX domain socket on linux and file socket on Mac OS X. Not used here, present only for compatibility with other powerline clients. This argument must always be the first one and be in a form `--socket ADDRESS\': no `=\' or short form allowed (in other powerline clients, not here).')
|
||||
|
|
|
@ -12,14 +12,14 @@ class ShellPowerline(Powerline):
|
|||
|
||||
def load_main_config(self):
|
||||
r = super(ShellPowerline, self).load_main_config()
|
||||
if self.args.config:
|
||||
mergedicts(r, self.args.config)
|
||||
if self.args.config_override:
|
||||
mergedicts(r, self.args.config_override)
|
||||
return r
|
||||
|
||||
def load_theme_config(self, name):
|
||||
r = super(ShellPowerline, self).load_theme_config(name)
|
||||
if self.args.theme_option and name in self.args.theme_option:
|
||||
mergedicts(r, self.args.theme_option[name])
|
||||
if self.args.theme_override and name in self.args.theme_override:
|
||||
mergedicts(r, self.args.theme_override[name])
|
||||
return r
|
||||
|
||||
def get_config_paths(self):
|
||||
|
|
|
@ -75,8 +75,8 @@ def render(args, environ, cwd):
|
|||
key = (
|
||||
args.ext[0],
|
||||
args.renderer_module,
|
||||
tuple(args.config) if args.config else None,
|
||||
tuple(args.theme_option) if args.theme_option else None,
|
||||
tuple(args.config_override) if args.config_override else None,
|
||||
tuple(args.theme_override) if args.theme_override else None,
|
||||
tuple(args.config_path) if args.config_path else None,
|
||||
)
|
||||
finish_args(args)
|
||||
|
|
|
@ -23,8 +23,8 @@ class Pl(object):
|
|||
|
||||
|
||||
class Args(object):
|
||||
theme_option = {}
|
||||
config = None
|
||||
theme_override = {}
|
||||
config_override = {}
|
||||
config_path = None
|
||||
ext = ['shell']
|
||||
renderer_module = None
|
||||
|
|
|
@ -41,8 +41,8 @@ class TestParser(TestCase):
|
|||
(['shell', '--width'], 'expected one argument'),
|
||||
(['shell', '--last-exit-code'], 'expected one argument'),
|
||||
(['shell', '--last-pipe-status'], 'expected one argument'),
|
||||
(['shell', '--config'], 'expected one argument'),
|
||||
(['shell', '--theme-option'], 'expected one argument'),
|
||||
(['shell', '--config-override'], 'expected one argument'),
|
||||
(['shell', '--theme-override'], 'expected one argument'),
|
||||
(['shell', '--config-path'], 'expected one argument'),
|
||||
(['shell', '--renderer-arg'], 'expected one argument'),
|
||||
(['shell', '--jobnum'], 'expected one argument'),
|
||||
|
@ -85,8 +85,8 @@ class TestParser(TestCase):
|
|||
'last_pipe_status': [10, 20, 30],
|
||||
'jobnum': 10,
|
||||
'width': 100,
|
||||
'config': {'common': {'term_truecolor': True, 'spaces': 4}},
|
||||
'theme_option': {
|
||||
'config_override': {'common': {'term_truecolor': True, 'spaces': 4}},
|
||||
'theme_override': {
|
||||
'default': {
|
||||
'segment_data': {
|
||||
'hostname': {
|
||||
|
@ -103,7 +103,7 @@ class TestParser(TestCase):
|
|||
(['shell', '-R', 'arg='], {'ext': ['shell'], 'renderer_arg': {}}),
|
||||
(['shell', '-t', 'default.segment_info={"hostname": {}}'], {
|
||||
'ext': ['shell'],
|
||||
'theme_option': {
|
||||
'theme_override': {
|
||||
'default': {
|
||||
'segment_info': {
|
||||
'hostname': {}
|
||||
|
@ -111,7 +111,7 @@ class TestParser(TestCase):
|
|||
}
|
||||
},
|
||||
}),
|
||||
(['shell', '-c', 'common={ }'], {'ext': ['shell'], 'config': {'common': {}}}),
|
||||
(['shell', '-c', 'common={ }'], {'ext': ['shell'], 'config_override': {'common': {}}}),
|
||||
]:
|
||||
args = parser.parse_args(argv)
|
||||
finish_args(args)
|
||||
|
|
|
@ -138,7 +138,7 @@ class TestConfig(TestCase):
|
|||
|
||||
def test_bash(self):
|
||||
from powerline.shell import ShellPowerline
|
||||
args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='.bash', config={'ext': {'shell': {'theme': 'default_leftonly'}}})
|
||||
args = Args(last_exit_code=1, jobnum=0, ext=['shell'], renderer_module='.bash', config_override={'ext': {'shell': {'theme': 'default_leftonly'}}})
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
powerline.render(segment_info={'args': args})
|
||||
with ShellPowerline(args, logger=get_logger(), run_once=False) as powerline:
|
||||
|
|
Loading…
Reference in New Issue