changeset 0:685cb4aa66f7 draft

Init
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 09 Sep 2013 10:21:03 -0400
parents
children d5300f96f9a2
files lol.py session sh-replay
diffstat 3 files changed, 103 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/lol.py
@@ -0,0 +1,22 @@
+from mercurial import revset
+
+def extsetup():
+    revset.symbols.update({ 'lol': revset_lol })
+
+def revset_lol(repo, subset, x):
+    '''``lol()``
+    Select changesets that have lolsy revision numbers
+    '''
+    args = revset.getargs(x, 0, 0, "lol takes no arguments")
+    return lolsy(subset)
+
+def lolsy(subset):
+    lol = pi(max(subset))
+    return [x for x in subset if x in lol]
+
+def pi(n):
+    lol = [2]
+    for i in range(3, n+1):
+        if all([i % p != 0 for p in [p for p in lol if p**2 <= n]]):
+            lol.append(i)
+    return lol
new file mode 100644
--- /dev/null
+++ b/session
@@ -0,0 +1,5 @@
+cd /home/jordi
+cd coding/vcs/octave-devel
+# a comment
+hg log
+git help revisions
new file mode 100755
--- /dev/null
+++ b/sh-replay
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+
+import os,sys,subprocess
+from colors import yellow, blue, magenta
+from sh import hg, cd
+
+def getch():
+    import sys, tty, termios
+    fd = sys.stdin.fileno()
+    old_settings = termios.tcgetattr(fd)
+    try:
+        tty.setraw(sys.stdin.fileno())
+        ch = sys.stdin.read(1)
+    finally:
+        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+    if ord(ch) == 3:
+        sys.exit(0)
+    return ch
+
+def get_hg_id():
+    try:
+        book = hg.id(B=True).strip()
+    except:
+        book = False
+
+    if book:
+        return book
+
+    try:
+        branch = hg.branch().strip()
+    except:
+        return ""
+
+    return branch
+
+def print_prompt():
+    cwd = os.getcwd()
+    if cwd == "/home/jordi":
+        cwd = "~"
+    else:
+        cwd = os.path.split(cwd)[-1]
+
+    hg_id = get_hg_id()
+
+    sys.stdout.write(yellow("jordi@Iris", style="bold") + ":"
+                     + blue(cwd, style="bold") + " "
+                     + magenta(hg_id, style="bold") + "$ ")
+
+def main():
+    with open(sys.argv[1]) as f:
+        cmds = [cmd.strip() for cmd in f.readlines()
+                if cmd.strip() and not cmd.strip().startswith("#")]
+
+
+    for cmd in cmds:
+        print_prompt()
+        for c in cmd:
+            key = getch()
+            sys.stdout.write(c)
+            sys.stdout.flush()
+
+        while True:
+            key = getch()
+            if ord(key) == 13:
+                break
+        if cmd.startswith("cd "):
+            cd(cmd[3:])
+        else:
+            subprocess.call(cmd, shell=True, executable="/bin/bash")
+
+        sys.stdout.write("\n")
+        sys.stdout.flush()
+
+if __name__ == "__main__":
+    main()
+