~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2009-11-11 07:34:02 UTC
  • mto: This revision was merged to the branch mainline in revision 735.
  • Revision ID: aaron@aaronbentley.com-20091111073402-s9uxn8znscvmaugx
Merge fetch-ghosts fix from Max Bowsher

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib import osutils
28
28
from bzrlib.branch import Branch
29
29
from bzrlib.config import config_dir, ensure_config_dir_exists
30
 
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
 
30
from bzrlib.commands import get_cmd_object, all_command_names, get_alias
31
31
from bzrlib.errors import BzrError
32
32
from bzrlib.workingtree import WorkingTree
33
33
 
99
99
        self.identchars += '-'
100
100
        ensure_config_dir_exists()
101
101
        self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
102
 
        readline.set_completer_delims(string.whitespace)
 
102
        whitespace = ''.join(c for c in string.whitespace if c < chr(127))
 
103
        readline.set_completer_delims(whitespace)
103
104
        if os.access(self.history_file, os.R_OK) and \
104
105
            os.path.isfile(self.history_file):
105
106
            readline.read_history_file(self.history_file)
168
169
        self.default("help "+line)
169
170
 
170
171
    def default(self, line):
171
 
        args = shlex.split(line)
 
172
        try:
 
173
            args = shlex.split(line)
 
174
        except ValueError, e:
 
175
            print 'Parse error:', e
 
176
            return
 
177
 
172
178
        alias_args = get_alias(args[0])
173
179
        if alias_args is not None:
174
180
            args[0] = alias_args.pop(0)
223
229
def run_shell():
224
230
    try:
225
231
        prompt = PromptCmd()
226
 
        try:
227
 
            prompt.cmdloop()
228
 
        finally:
229
 
            prompt.write_history()
 
232
        while True:
 
233
            try:
 
234
                try:
 
235
                    prompt.cmdloop()
 
236
                except KeyboardInterrupt:
 
237
                    print
 
238
            finally:
 
239
                prompt.write_history()
230
240
    except StopIteration:
231
241
        pass
232
242
 
280
290
 
281
291
 
282
292
def iter_command_names(hidden=False):
283
 
    for real_cmd_name, cmd_class in get_all_cmds():
284
 
        if not hidden and cmd_class.hidden:
 
293
    for real_cmd_name in all_command_names():
 
294
        cmd_obj = get_cmd_object(real_cmd_name)
 
295
        if not hidden and cmd_obj.hidden:
285
296
            continue
286
 
        for name in [real_cmd_name] + cmd_class.aliases:
 
297
        for name in [real_cmd_name] + cmd_obj.aliases:
287
298
            # Don't complete on aliases that are prefixes of the canonical name
288
299
            if name == real_cmd_name or not real_cmd_name.startswith(name):
289
300
                yield name