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.
This commit is contained in:
Kim Silkebækken 2013-01-28 17:29:02 +01:00
parent 5db6f47562
commit 29793259e1
2 changed files with 5 additions and 6 deletions

View File

@ -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

View File

@ -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()