--- 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)