diff --git a/mncli.py b/mncli.py index 5a45c7a..963db3b 100644 --- a/mncli.py +++ b/mncli.py @@ -3,6 +3,7 @@ import sys from itertools import imap import os.path from pprint import pprint +import atexit from dirset import DirSet from messagenet import Messagenet @@ -42,20 +43,33 @@ def main(): conf.update(json.load(open(sys.argv[1]))) user, password = read_pass_file(conf['credfile']) with Messagenet() as mn: # conf['browserdriver']) - mn.login(user, password) # readline {{{2 try: import readline readline.read_init_file() - readline.read_history_file(os.path.join( - os.path.dirname(os.path.realpath(__file__)), - '.mncli_history')) except ImportError: # readline not supported on your system pass except: print "Some error with readline; who cares" + histfile = os.path.join(os.path.dirname(__file__), + '.mncli_history') + if os.path.exists(histfile): + readline.read_history_file(histfile) + atexit.register(readline.write_history_file, histfile) + + def _completer(text, state): + commands = ('help', 'quit', 'calllog', 'forward', 'currency') + options = [c for c in commands if c.startswith(text)] + if readline.get_begidx() != 0: + return None + if state < len(options): + return options[state] + return None + readline.parse_and_bind('tab: complete') + readline.set_completer(_completer) # }}} + mn.login(user, password) print "messagenet command-line. type help for help. type quit for quit" while True: try: @@ -91,6 +105,8 @@ def main(): else: print " Invalid command '%s'; type 'help' to get help" % cmd - # save_calls(calls, conf['datadir']) + +if __name__ == '__main__': + main() # vim: set fdm=marker: