From d62336f7a29b5fd9459def0c691dde3362bcfc53 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 29 Nov 2014 19:08:59 +0300 Subject: [PATCH] Add a way to specify configuration paths to powerline-config One still cannot override various configuration options from the command-line. --- powerline/bindings/config.py | 5 +++-- powerline/commands/config.py | 1 + powerline/tmux.py | 16 ++++++++++++++++ tests/test_shells/input.tmux | 4 ++++ tests/test_shells/tmux.conf | 2 ++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 powerline/tmux.py create mode 100644 tests/test_shells/input.tmux create mode 100644 tests/test_shells/tmux.conf diff --git a/powerline/bindings/config.py b/powerline/bindings/config.py index 042d8087..169d1507 100644 --- a/powerline/bindings/config.py +++ b/powerline/bindings/config.py @@ -7,7 +7,8 @@ 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, Powerline +from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config +from powerline.tmux import TmuxPowerline from powerline.lib.shell import which from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, get_tmux_version from powerline.lib.encoding import get_preferred_output_encoding @@ -77,7 +78,7 @@ def source_tmux_files(pl, args): def init_color_variables(pl, args): - powerline = Powerline('tmux') + powerline = TmuxPowerline(args.config_path) # TODO Move configuration files loading out of Powerline object and use it # directly powerline.update_renderer() diff --git a/powerline/commands/config.py b/powerline/commands/config.py index f096ab99..9092d6ba 100644 --- a/powerline/commands/config.py +++ b/powerline/commands/config.py @@ -43,6 +43,7 @@ class ConfigArgParser(argparse.ArgumentParser): def get_argparser(ArgumentParser=ConfigArgParser): parser = ArgumentParser(description='Script used to obtain powerline configuration.') + 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.') subparsers = parser.add_subparsers() tmux_parser = subparsers.add_parser('tmux', help='Tmux-specific commands') tmux_parser.add_argument( diff --git a/powerline/tmux.py b/powerline/tmux.py new file mode 100644 index 00000000..15f42127 --- /dev/null +++ b/powerline/tmux.py @@ -0,0 +1,16 @@ +# 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() diff --git a/tests/test_shells/input.tmux b/tests/test_shells/input.tmux new file mode 100644 index 00000000..d6364d16 --- /dev/null +++ b/tests/test_shells/input.tmux @@ -0,0 +1,4 @@ +echo $TMUX +exit +kill-server + diff --git a/tests/test_shells/tmux.conf b/tests/test_shells/tmux.conf new file mode 100644 index 00000000..1f5143f5 --- /dev/null +++ b/tests/test_shells/tmux.conf @@ -0,0 +1,2 @@ +source powerline/bindings/tmux/powerline.conf +set -g default-shell tests/shell/path/dash