~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Adeodato Simó
  • Date: 2006-07-12 18:17:03 UTC
  • mto: This revision was merged to the branch mainline in revision 416.
  • Revision ID: dato@net.com.org.es-20060712181703-af9e1c81c08d3af3
Make clean-tree --detritus or --ignored not delete also unknown files,
and add --unknown, noting it's the default option.

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))
83
 
            return completions
 
77
                completions.extend([f+" " for f in 
 
78
                                    filter_completions(iter, self.text)])
 
79
            return completions 
84
80
 
85
81
 
86
82
class PromptCmd(cmd.Cmd):
122
118
    def set_prompt(self):
123
119
        if self.tree is not None:
124
120
            try:
125
 
                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(),
126
 
                               self.tree.relpath('.'))
 
121
                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(), 
 
122
                               self.tree.branch.relpath('.'))
127
123
                prompt = " %s:%d/%s" % prompt_data
128
124
            except:
129
125
                prompt = ""
168
164
        alias_args = get_alias(args[0])
169
165
        if alias_args is not None:
170
166
            args[0] = alias_args.pop(0)
171
 
 
 
167
            
172
168
        commandname = args.pop(0)
173
169
        for char in ('|', '<', '>'):
174
170
            commandname = commandname.split(char)[0]
200
196
 
201
197
    def completedefault(self, text, line, begidx, endidx):
202
198
        """Perform completion for native commands.
203
 
 
 
199
        
204
200
        :param text: The text to complete
205
201
        :type text: str
206
202
        :param line: The entire line to complete
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