~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2008-10-08 13:55:13 UTC
  • Revision ID: aaron@aaronbentley.com-20081008135513-wjxlb9sgh9ua0edb
Publish getchar

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2004, 2005 Aaron Bentley
2
 
# <aaron.bentley@utoronto.ca>
 
2
# <aaron@aaronbentley.com>
3
3
#
4
4
#    This program is free software; you can redistribute it and/or modify
5
5
#    it under the terms of the GNU General Public License as published by
24
24
import string
25
25
import sys
26
26
 
 
27
from bzrlib import osutils
27
28
from bzrlib.branch import Branch
 
29
from bzrlib.config import config_dir, ensure_config_dir_exists
28
30
from bzrlib.commands import get_cmd_object, get_all_cmds, get_alias
29
31
from bzrlib.errors import BzrError
30
32
from bzrlib.workingtree import WorkingTree
80
82
            else:
81
83
                iter = iter_file_completions(self.text)
82
84
                completions.extend(filter_completions(iter, self.text))
83
 
            return completions 
 
85
            return completions
84
86
 
85
87
 
86
88
class PromptCmd(cmd.Cmd):
 
89
 
87
90
    def __init__(self):
88
91
        cmd.Cmd.__init__(self)
89
92
        self.prompt = "bzr> "
94
97
        self.set_title()
95
98
        self.set_prompt()
96
99
        self.identchars += '-'
97
 
        self.history_file = os.path.expanduser("~/.bazaar/shell-history")
 
100
        ensure_config_dir_exists()
 
101
        self.history_file = osutils.pathjoin(config_dir(), 'shell-history')
98
102
        readline.set_completer_delims(string.whitespace)
99
103
        if os.access(self.history_file, os.R_OK) and \
100
104
            os.path.isfile(self.history_file):
122
126
    def set_prompt(self):
123
127
        if self.tree is not None:
124
128
            try:
125
 
                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(), 
 
129
                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(),
126
130
                               self.tree.relpath('.'))
127
131
                prompt = " %s:%d/%s" % prompt_data
128
132
            except:
168
172
        alias_args = get_alias(args[0])
169
173
        if alias_args is not None:
170
174
            args[0] = alias_args.pop(0)
171
 
            
 
175
 
172
176
        commandname = args.pop(0)
173
177
        for char in ('|', '<', '>'):
174
178
            commandname = commandname.split(char)[0]
200
204
 
201
205
    def completedefault(self, text, line, begidx, endidx):
202
206
        """Perform completion for native commands.
203
 
        
 
207
 
204
208
        :param text: The text to complete
205
209
        :type text: str
206
210
        :param line: The entire line to complete