~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

Merged shell readline fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import cmd
19
19
from itertools import chain
20
20
import os
21
 
import readline
 
21
try:
 
22
    import readline
 
23
except ImportError:
 
24
    _has_readline = False
 
25
else:
 
26
    _has_readline = True
22
27
import shlex
23
28
import stat
24
29
import string
100
105
        ensure_config_dir_exists()
101
106
        self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
102
107
        whitespace = ''.join(c for c in string.whitespace if c < chr(127))
103
 
        readline.set_completer_delims(whitespace)
104
 
        if os.access(self.history_file, os.R_OK) and \
105
 
            os.path.isfile(self.history_file):
106
 
            readline.read_history_file(self.history_file)
 
108
        if _has_readline:
 
109
            readline.set_completer_delims(whitespace)
 
110
            if os.access(self.history_file, os.R_OK) and \
 
111
                os.path.isfile(self.history_file):
 
112
                readline.read_history_file(self.history_file)
107
113
        self.cwd = os.getcwd()
108
114
 
109
115
    def write_history(self):
110
 
        readline.write_history_file(self.history_file)
 
116
        if _has_readline:
 
117
            readline.write_history_file(self.history_file)
111
118
 
112
119
    def do_quit(self, args):
113
120
        self.write_history()