~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2006-07-17 19:05:46 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060717190546-11b67e418c7c3241
Allow completion on executables, fix broken prompt code

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
23
24
import string
24
25
import sys
25
26
 
26
27
from bzrlib.branch import Branch
27
28
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
28
29
from bzrlib.errors import BzrError
 
30
from bzrlib.workingtree import WorkingTree
29
31
 
30
32
import terminal
31
33
 
64
66
 
65
67
    def get_completions_or_raise(self):
66
68
        if self.command is None:
67
 
            iter = (c+" " for c in iter_command_names() if
68
 
                    c not in COMPLETION_BLACKLIST)
 
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)
69
74
            return list(filter_completions(iter, self.text))
70
75
        if self.prev_opt is None:
71
76
            completions = self.get_option_completions()
118
123
        if self.tree is not None:
119
124
            try:
120
125
                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(), 
121
 
                               self.tree.branch.relpath('.'))
 
126
                               self.tree.relpath('.'))
122
127
                prompt = " %s:%d/%s" % prompt_data
123
128
            except:
124
129
                prompt = ""
280
285
                yield name
281
286
 
282
287
 
 
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
 
283
299
def filter_completions(iter, arg):
284
300
    return (c for c in iter if c.startswith(arg))
285
301