048db3b4a2a4

Add two tags.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 19 Jun 2009 19:12:46 -0400
parents e1ea36d1bf0f
children 17b2a4fda87a
branches/tags (none)
files prompt.py

Changes

diff -r e1ea36d1bf0f -r 048db3b4a2a4 prompt.py
--- a/prompt.py	Fri Jun 19 18:12:33 2009 -0400
+++ b/prompt.py	Fri Jun 19 19:12:46 2009 -0400
@@ -7,11 +7,24 @@
 a bash prompt.
 '''
 
-from mercurial import hg
+import re
+
 
 def prompt(ui, repo, fs):
     """Take a format string, parse any variables, and output the result."""
-    ui.write(fs)
+    
+    def _status(m):
+        stat = repo.status()[:4]
+        return '!' if any(stat[:3]) else '?' if stat[-1] else ''
+    
+    patterns = {
+        r'\{branch\}': lambda m: repo[-1].branch(),
+        r'\{status\}': _status,
+    }
+    
+    for pattern, repl in patterns.items():
+        fs = re.sub(pattern, repl, fs)
+    print fs
 
 cmdtable = {
     # "command-name": (function-call, options-list, help-string)