Skip to content

Commit 65e7a0e

Browse files
author
Bob Farrell
committed
History file support added.
Defaults to ~/.pythonhist but can be configured in rc (see sample-rc) committer: Bob Farrell <bob@keys.(none)>
1 parent 0a9df3f commit 65e7a0e

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

‎CHANGELOG‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v0.7.1
2+
======
3+
Added support for a history file, defaults to ~/.pythonhist and 100 lines but
4+
is configurable from the rc file (see sample-rc).
5+
16
v0.7.0
27
======
38
C-d behaviour changed so it no longer exits if the current line isn't empty.

‎bpython.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# bpython 0.7.0::fancy curses interface to the Python repl::Bob Farrell 2008
2+
# bpython 0.7.1::fancy curses interface to the Python repl::Bob Farrell 2008
33
#
44
# The MIT License
55
#
@@ -101,6 +101,8 @@ def readlines(self, x):
101101
OPTS.auto_display_list = True
102102
OPTS.syntax = True
103103
OPTS.arg_spec = True
104+
OPTS.hist_file = '~/.pythonhist'
105+
OPTS.hist_length = 100
104106

105107
# TODO:
106108
#
@@ -246,6 +248,10 @@ def __init__( self, scr, interp, statusbar=None, idle=None):
246248
if not OPTS.arg_spec:
247249
return
248250

251+
pythonhist = os.path.expanduser('~/.pythonhist')
252+
if os.path.exists(pythonhist):
253+
self.rl_hist = open(pythonhist, 'r').readlines()
254+
249255
pexp = Forward()
250256
chars = printables.replace('(', '')
251257
chars = chars.replace(')', '')
@@ -829,7 +835,8 @@ def repl( self ):
829835
self.s_hist[-1] += self.f_string
830836
self.stdout_hist += inp + '\n'
831837
# Keep two copies so you can go up and down in the hist:
832-
self.rl_hist.append( inp )
838+
if inp:
839+
self.rl_hist.append( inp + '\n' )
833840
more = self.push( inp )
834841

835842
def size( self ):
@@ -1566,6 +1573,11 @@ def main( scr ):
15661573

15671574

15681575
repl.repl()
1576+
if OPTS.hist_length:
1577+
f = open(os.path.expanduser('~/.pythonhist'), 'w')
1578+
f.writelines(repl.rl_hist[-OPTS.hist_length:])
1579+
f.close()
1580+
15691581
return repl.getstdout()
15701582

15711583
if __name__ == '__main__':

‎sample-rc‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ syntax = on
1313
# Display the arg spec (list of arguments) for callables,
1414
# when possible (default: on).
1515
arg_spec = true
16+
17+
# History file:
18+
hist_file = ~/.pythonhist
19+
20+
# Number of lines to store in history (set to 0 to disable):
21+
hist_len = 100
22+
23+
# Soft tab size:
24+
tab_length = 4
25+

0 commit comments

Comments
 (0)