~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2006-07-01 22:25:01 UTC
  • mfrom: (408.1.1 bzrtools)
  • Revision ID: aaron.bentley@utoronto.ca-20060701222501-a5dfbdeacbccd2da
Update colordiff to use wrapped versions of diff

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
import shlex
22
23
import string
23
 
from itertools import chain
 
24
import sys
 
25
 
 
26
from bzrlib.branch import Branch
 
27
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
24
28
from bzrlib.errors import BzrError
25
 
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
26
 
from bzrlib.branch import Branch
 
29
 
 
30
import terminal
 
31
 
27
32
 
28
33
SHELL_BLACKLIST = set(['rm', 'ls'])
29
34
COMPLETION_BLACKLIST = set(['shell'])
30
35
 
 
36
 
31
37
class BlackListedCommand(BzrError):
32
38
    def __init__(self, command):
33
39
        BzrError.__init__(self, "The command %s is blacklisted for shell use" %
34
40
                          command)
35
41
 
 
42
 
36
43
class CompletionContext(object):
37
44
    def __init__(self, text, command=None, prev_opt=None, arg_pos=None):
38
45
        self.text = text
153
160
        self.default("help "+line)
154
161
 
155
162
    def default(self, line):
156
 
        args = line.split()
 
163
        args = shlex.split(line)
157
164
        alias_args = get_alias(args[0])
158
165
        if alias_args is not None:
159
166
            args[0] = alias_args.pop(0)
204
211
            cmd = None
205
212
        return CompletionContext(text, command=cmd).get_completions()
206
213
 
 
214
 
207
215
def run_shell():
208
216
    try:
209
217
        prompt = PromptCmd()
214
222
    except StopIteration:
215
223
        pass
216
224
 
 
225
 
217
226
def iter_opt_completions(command_obj):
218
227
    for option_name, option in command_obj.options().items():
219
228
        yield "--" + option_name
221
230
        if short_name:
222
231
            yield "-" + short_name
223
232
 
 
233
 
224
234
def iter_file_completions(arg, only_dirs = False):
225
235
    """Generate an iterator that iterates through filename completions.
226
236
 
260
270
    """
261
271
    return iter_file_completions(arg, True)
262
272
 
 
273
 
263
274
def iter_command_names(hidden=False):
264
275
    for real_cmd_name, cmd_class in get_all_cmds():
265
276
        if not hidden and cmd_class.hidden:
269
280
            if name == real_cmd_name or not real_cmd_name.startswith(name):
270
281
                yield name
271
282
 
 
283
 
272
284
def filter_completions(iter, arg):
273
285
    return (c for c in iter if c.startswith(arg))
274
286
 
 
287
 
275
288
def iter_munged_completions(iter, arg, text):
276
289
    for completion in iter:
277
290
        completion = str(completion)
278
291
        if completion.startswith(arg):
279
292
            yield completion[len(arg)-len(text):]+" "
280
293
 
 
294
 
281
295
def too_complicated(line):
282
 
    for char in '|<>"\"*?':
 
296
    for char in '|<>*?':
283
297
        if char in line:
284
298
            return True
285
299
    return False