initial checkin
[zsh-lovers.git] / zsh_people / bruno_bonfils / bin / zshist
1 #! /usr/bin/python
2
3 import sys, os, string, time
4 import locale
5 locale.setlocale(locale.LC_ALL,"")
6
7 #some default definitions
8 colours = {    
9             'none'       :    "",
10             'default'    :    "\033[0m",
11             'bold'       :    "\033[1m",
12             'underline'  :    "\033[4m",
13             'blink'      :    "\033[5m",
14             'reverse'    :    "\033[7m",
15             'concealed'  :    "\033[8m",
16
17             'black'      :    "\033[30m", 
18             'red'        :    "\033[31m",
19             'green'      :    "\033[32m",
20             'yellow'     :    "\033[33m",
21             'blue'       :    "\033[34m",
22             'magenta'    :    "\033[35m",
23             'cyan'       :    "\033[36m",
24             'white'      :    "\033[37m",
25
26             'on_black'   :    "\033[40m", 
27             'on_red'     :    "\033[41m",
28             'on_green'   :    "\033[42m",
29             'on_yellow'  :    "\033[43m",
30             'on_blue'    :    "\033[44m",
31             'on_magenta' :    "\033[45m",
32             'on_cyan'    :    "\033[46m",
33             'on_white'   :    "\033[47m",
34
35             'beep'       :    "\007"
36             }
37
38
39 timeformat = "%a %b %d %H:%M:%S %Y"
40 delim1 = colours["bold"]+colours["red"] # before time string
41 delim2 = colours["default"]+colours["yellow"]+":" # after time string
42 delim3 = ": "+colours["default"] # before command
43 delim4 = colours["default"] # at the end of line
44 delim5 = colours["bold"]+colours["blue"] # before unrecognized line format
45
46
47 for i in [ os.environ['HOME']+"/.zsh/misc/zshistrc"]:
48     if os.path.isfile(i):
49         execfile(i)
50
51
52 if len(sys.argv) > 1:
53     historyfile = sys.argv[1]
54     if os.path.isdir(historyfile):
55         historyfile = historyfile + "/.zsh/history"
56 else:
57     historyfile = os.environ['HOME']+"/.zsh/history"
58
59 f = open(historyfile,"r")
60 l = f.readlines()
61 for i in l:
62     try:
63         s1 = string.split(i, ":",2)
64         timestring = s1[1]
65         s2 = string.split(s1[2], ";", 1)
66         delaystring = s2[0]
67         commandstring = s2[1][:-1]
68         t = long(timestring) # seconds since the epoch
69         print delim1+time.strftime(timeformat,time.localtime(t))+delim2+delaystring+delim3+commandstring+delim4
70     except:
71         print delim5+i[:-1]+delim4
72