From 29793259e10a2815099cd2c81eca6c7d5108588a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20Silkeb=C3=A6kken?= Date: Mon, 28 Jan 2013 17:29:02 +0100 Subject: [PATCH] Improve argument handling in powerline script Modules can now be any string, and an informative error message will be written to sys.stdout if the module doesn't exist. The `last_pipe_status` argument will also automatically be split into a list. --- powerline/segments/shell.py | 5 ++--- scripts/powerline | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/powerline/segments/shell.py b/powerline/segments/shell.py index 59a33fc0..5b45b02c 100644 --- a/powerline/segments/shell.py +++ b/powerline/segments/shell.py @@ -7,10 +7,9 @@ last_status.requires_powerline_segment_info = True def last_pipe_status(segment_info): - pipe_status = [int(status) for status in segment_info.last_pipe_status.split()] - if any(pipe_status): + if any(segment_info.last_pipe_status): return [{"contents": str(status), "highlight_group": "exit_fail" if status else "exit_success"} - for status in pipe_status] + for status in segment_info.last_pipe_status] else: return None last_pipe_status.requires_powerline_segment_info = True diff --git a/scripts/powerline b/scripts/powerline index 2fc4c956..fb2d4bc1 100755 --- a/scripts/powerline +++ b/scripts/powerline @@ -14,10 +14,10 @@ except ImportError: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('ext', nargs=1) parser.add_argument('side', nargs='?', choices=('left', 'right')) -parser.add_argument('-r', '--renderer_module', choices=('shell', 'zsh_prompt', 'tmux')) +parser.add_argument('-r', '--renderer_module', metavar='MODULE', type=str) parser.add_argument('-w', '--width', type=int) -parser.add_argument('--last_exit_code', type=int, metavar='INT') -parser.add_argument('--last_pipe_status', metavar='LIST') +parser.add_argument('--last_exit_code', metavar='INT', type=int) +parser.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()]) if __name__ == '__main__': args = parser.parse_args()