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