~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2006-07-13 13:25:20 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060713132520-2fabfab51affb82f
Update clean-tree docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import os
21
21
import readline
22
22
import shlex
23
 
import stat
24
23
import string
25
24
import sys
26
25
 
27
26
from bzrlib.branch import Branch
28
27
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
29
28
from bzrlib.errors import BzrError
30
 
from bzrlib.workingtree import WorkingTree
31
29
 
32
30
import terminal
33
31
 
66
64
 
67
65
    def get_completions_or_raise(self):
68
66
        if self.command is None:
69
 
            if '/' in self.text:
70
 
                iter = iter_executables(self.text)
71
 
            else:
72
 
                iter = (c+" " for c in iter_command_names() if
73
 
                        c not in COMPLETION_BLACKLIST)
 
67
            iter = (c+" " for c in iter_command_names() if
 
68
                    c not in COMPLETION_BLACKLIST)
74
69
            return list(filter_completions(iter, self.text))
75
70
        if self.prev_opt is None:
76
71
            completions = self.get_option_completions()
79
74
                completions.extend(list(filter_completions(iter, self.text)))
80
75
            else:
81
76
                iter = iter_file_completions(self.text)
82
 
                completions.extend(filter_completions(iter, self.text))
 
77
                completions.extend([f+" " for f in 
 
78
                                    filter_completions(iter, self.text)])
83
79
            return completions 
84
80
 
85
81
 
123
119
        if self.tree is not None:
124
120
            try:
125
121
                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(), 
126
 
                               self.tree.relpath('.'))
 
122
                               self.tree.branch.relpath('.'))
127
123
                prompt = " %s:%d/%s" % prompt_data
128
124
            except:
129
125
                prompt = ""
263
259
                userfile+='/'
264
260
                yield userfile
265
261
            elif not only_dirs:
266
 
                yield userfile + ' '
 
262
                yield userfile
267
263
 
268
264
 
269
265
def iter_dir_completions(arg):
285
281
                yield name
286
282
 
287
283
 
288
 
def iter_executables(path):
289
 
    dirname, partial = os.path.split(path)
290
 
    for filename in os.listdir(dirname):
291
 
        if not filename.startswith(partial):
292
 
            continue
293
 
        fullpath = os.path.join(dirname, filename)
294
 
        mode=os.lstat(fullpath)[stat.ST_MODE]
295
 
        if stat.S_ISREG(mode) and 0111 & mode:
296
 
            yield fullpath + ' '
297
 
 
298
 
 
299
284
def filter_completions(iter, arg):
300
285
    return (c for c in iter if c.startswith(arg))
301
286