2014-05-24 11:44:58 +02:00
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
2014-08-31 20:55:26 +02:00
2014-05-24 11:44:58 +02:00
'''Script used to obtain powerline configuration'''
2014-08-31 20:55:26 +02:00
from __future__ import (unicode_literals, division, absolute_import, print_function)
2014-05-24 11:44:58 +02:00
import argparse
try:
import powerline.bindings.config as config
except ImportError:
2014-07-22 23:47:46 +02:00
import sys
import os
2014-05-24 11:44:58 +02:00
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(os.path.realpath(__file__)))))
2014-08-31 21:01:40 +02:00
import powerline.bindings.config as config
2014-05-24 11:44:58 +02:00
TMUX_ACTIONS = {
2014-07-10 19:13:39 +02:00
'source': config.source_tmux_files,
2014-05-24 11:44:58 +02:00
}
2014-08-02 18:07:55 +02:00
SHELL_ACTIONS = {
'command': config.shell_command,
2014-08-10 14:01:57 +02:00
'uses': config.uses,
2014-08-02 18:07:55 +02:00
}
2014-05-24 11:44:58 +02:00
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers()
tmux_parser = subparsers.add_parser('tmux', help='Tmux-specific commands')
tmux_parser.add_argument(
'function',
choices=tuple(TMUX_ACTIONS.values()),
metavar='action',
type=(lambda v: TMUX_ACTIONS.get(v)),
help='If action is "source" then version-specific tmux configuration files are sourced.'
)
2014-08-02 18:07:55 +02:00
shell_parser = subparsers.add_parser('shell', help='Shell-specific commands')
shell_parser.add_argument(
'function',
choices=tuple(SHELL_ACTIONS.values()),
type=(lambda v: SHELL_ACTIONS.get(v)),
2014-08-10 14:01:57 +02:00
metavar='action',
help='If action is "command" then preferred powerline command is output, if it is “uses” then powerline-config script will exit with 1 if specified component is disabled and 0 otherwise.',
)
shell_parser.add_argument(
'component',
nargs='?',
choices=('tmux', 'prompt'),
metavar='component',
)
shell_parser.add_argument(
'-s', '--shell',
nargs='?',
help='Shell for which query is run',
2014-08-02 18:07:55 +02:00
)
2014-05-24 11:44:58 +02:00
args = parser.parse_args()
2014-07-10 19:13:39 +02:00
pl = config.create_powerline_logger(args)
args.function(pl, args)