Rev 741: Custom prompt in http://bzr.arbash-meinel.com/plugins/bzrtools

John Arbash Meinel john at arbash-meinel.com
Thu Dec 17 22:08:42 GMT 2009


At http://bzr.arbash-meinel.com/plugins/bzrtools

------------------------------------------------------------
revno: 741
revision-id: john at arbash-meinel.com-20091217220823-ba2ysjpbuoixj84z
parent: john at arbash-meinel.com-20091217220727-dbt6e7dx0neytepf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: bzrtools
timestamp: Thu 2009-12-17 16:08:23 -0600
message:
  Custom prompt
-------------- next part --------------
=== modified file 'shell.py'
--- a/shell.py	2009-12-17 22:07:27 +0000
+++ b/shell.py	2009-12-17 22:08:23 +0000
@@ -25,7 +25,7 @@
 import sys
 import time
 
-from bzrlib import osutils
+from bzrlib import osutils, urlutils
 from bzrlib.branch import Branch
 from bzrlib.config import config_dir, ensure_config_dir_exists
 from bzrlib.commands import get_cmd_object, all_command_names, get_alias
@@ -95,6 +95,7 @@
             self.tree = WorkingTree.open_containing('.')[0]
         except:
             self.tree = None
+        self.cwd = os.getcwd()
         self.set_title()
         self.set_prompt()
         self.identchars += '-'
@@ -105,7 +106,6 @@
         if os.access(self.history_file, os.R_OK) and \
             os.path.isfile(self.history_file):
             readline.read_history_file(self.history_file)
-        self.cwd = os.getcwd()
 
     def write_history(self):
         readline.write_history_file(self.history_file)
@@ -122,20 +122,35 @@
         self.do_quit(args)
 
     def postcmd(self, line, bar):
-        self.set_title()
-        self.set_prompt()
+        if self.tree is not None:
+            self.tree.lock_read()
+        try:
+            self.set_title()
+            self.set_prompt()
+        finally:
+            if self.tree is not None:
+                self.tree.unlock()
 
     def set_prompt(self):
         if self.tree is not None:
             try:
-                prompt_data = (self.tree.branch.nick, self.tree.branch.revno(),
-                               self.tree.relpath('.'))
-                prompt = " %s:%d/%s" % prompt_data
-            except:
+                relpath = urlutils.determine_relative_path(
+                    self.tree.branch.repository.bzrdir.root_transport.base,
+                    self.tree.branch.base)
+                if relpath == '.':
+                    # Standalone
+                    semi_nick = osutils.basename(self.tree.branch.base)
+                else:
+                    semi_nick = relpath
+                tree_base = osutils.basename(self.tree.basedir)
+                prompt_data = (tree_base, self.tree.relpath('.'),
+                               semi_nick, self.tree.branch.revno())
+                prompt = "%s/%s {%s@%d}" % prompt_data
+            except BzrError:
                 prompt = ""
         else:
-            prompt = ""
-        self.prompt = "bzr%s> " % prompt
+            prompt = "%s" % (self.cwd,)
+        self.prompt = "%s\n> " % prompt
 
     def set_title(self, command=None):
         if self.tree is not None:



More information about the bazaar-commits mailing list