~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2006-06-23 18:19:25 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060623181925-ae3ff20c166cab49
Clean up style

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
#    You should have received a copy of the GNU General Public License
15
15
#    along with this program; if not, write to the Free Software
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
17
18
import cmd
18
 
import sys
 
19
from itertools import chain
19
20
import os
20
 
import terminal
21
21
import readline
22
22
import string
23
 
from itertools import chain
 
23
import sys
 
24
 
 
25
from bzrlib.branch import Branch
 
26
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
24
27
from bzrlib.errors import BzrError
25
 
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
26
 
from bzrlib.branch import Branch
 
28
 
 
29
import terminal
 
30
 
27
31
 
28
32
SHELL_BLACKLIST = set(['rm', 'ls'])
29
33
COMPLETION_BLACKLIST = set(['shell'])
30
34
 
 
35
 
31
36
class BlackListedCommand(BzrError):
32
37
    def __init__(self, command):
33
38
        BzrError.__init__(self, "The command %s is blacklisted for shell use" %
34
39
                          command)
35
40
 
 
41
 
36
42
class CompletionContext(object):
37
43
    def __init__(self, text, command=None, prev_opt=None, arg_pos=None):
38
44
        self.text = text
204
210
            cmd = None
205
211
        return CompletionContext(text, command=cmd).get_completions()
206
212
 
 
213
 
207
214
def run_shell():
208
215
    try:
209
216
        prompt = PromptCmd()
214
221
    except StopIteration:
215
222
        pass
216
223
 
 
224
 
217
225
def iter_opt_completions(command_obj):
218
226
    for option_name, option in command_obj.options().items():
219
227
        yield "--" + option_name
221
229
        if short_name:
222
230
            yield "-" + short_name
223
231
 
 
232
 
224
233
def iter_file_completions(arg, only_dirs = False):
225
234
    """Generate an iterator that iterates through filename completions.
226
235
 
260
269
    """
261
270
    return iter_file_completions(arg, True)
262
271
 
 
272
 
263
273
def iter_command_names(hidden=False):
264
274
    for real_cmd_name, cmd_class in get_all_cmds():
265
275
        if not hidden and cmd_class.hidden:
269
279
            if name == real_cmd_name or not real_cmd_name.startswith(name):
270
280
                yield name
271
281
 
 
282
 
272
283
def filter_completions(iter, arg):
273
284
    return (c for c in iter if c.startswith(arg))
274
285
 
 
286
 
275
287
def iter_munged_completions(iter, arg, text):
276
288
    for completion in iter:
277
289
        completion = str(completion)
278
290
        if completion.startswith(arg):
279
291
            yield completion[len(arg)-len(text):]+" "
280
292
 
 
293
 
281
294
def too_complicated(line):
282
295
    for char in '|<>"\"*?':
283
296
        if char in line: