##// END OF EJS Templates
`ipython history clear` subcommand
Paul Ivanov -
Show More
@@ -12,6 +12,7 b' import sqlite3'
12 12 from IPython.config.application import Application
13 13 from IPython.core.application import BaseIPythonApplication
14 14 from IPython.utils.traitlets import Bool, Int, Dict
15 from IPython.utils.io import ask_yes_no
15 16
16 17 trim_hist_help = """Trim the IPython history database to the last 1000 entries.
17 18
@@ -20,6 +21,16 b' the old file with the new. Use the `--keep=` argument to specify a number'
20 21 other than 1000.
21 22 """
22 23
24 clear_hist_help = """Clear the IPython history database, deleting all entries.
25
26 Because this is a destructive operation, IPython will prompt the user if they
27 really want to do this. Passing a `-f` flag will force clearing without a
28 prompt.
29
30 This is an handy alias to `ipython history trim --keep=0`
31 """
32
33
23 34 class HistoryTrim(BaseIPythonApplication):
24 35 description = trim_hist_help
25 36
@@ -105,6 +116,27 b' class HistoryTrim(BaseIPythonApplication):'
105 116
106 117 os.rename(new_hist_file, hist_file)
107 118
119 class HistoryClear(HistoryTrim):
120 description = clear_hist_help
121 keep = Int(0, config=False,
122 help="Number of recent lines to keep in the database.")
123
124 force = Bool(False, config=True,
125 help="Don't prompt user for confirmation")
126
127 flags = Dict(dict(
128 force = ({'HistoryClear' : {'force' : True}},
129 force.get_metadata('help')),
130 f = ({'HistoryTrim' : {'force' : True}},
131 force.get_metadata('help')
132 )
133 ))
134 aliases = Dict()
135
136 def start(self):
137 if self.force or ask_yes_no("Really delete all ipython history? ",
138 default="no", interrupt="no"):
139 HistoryTrim.start(self)
108 140
109 141 class HistoryApp(Application):
110 142 name = u'ipython-history'
@@ -112,6 +144,7 b' class HistoryApp(Application):'
112 144
113 145 subcommands = Dict(dict(
114 146 trim = (HistoryTrim, HistoryTrim.description.splitlines()[0]),
147 clear = (HistoryClear, HistoryClear.description.splitlines()[0]),
115 148 ))
116 149
117 150 def start(self):
General Comments 0
You need to be logged in to leave comments. Login now