Skip to content

Commit 1be2e4b

Browse files
committed
Always remove persistent history file when history is cleared since it no longer is dependent on readline.
Made certain paths absolute since the CWD could change between usages.
1 parent 808eae6 commit 1be2e4b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cmd2/cmd2.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, persistent
468468

469469
# If a startup script is provided, then add it in the queue to load
470470
if startup_script is not None:
471-
startup_script = os.path.expanduser(startup_script)
471+
startup_script = os.path.abspath(os.path.expanduser(startup_script))
472472
if os.path.exists(startup_script) and os.path.getsize(startup_script) > 0:
473473
self.cmdqueue.append("load '{}'".format(startup_script))
474474

@@ -3371,10 +3371,11 @@ def do_history(self, args: argparse.Namespace) -> None:
33713371
# Clear command and readline history
33723372
self.history.clear()
33733373

3374+
if self.persistent_history_file:
3375+
os.remove(self.persistent_history_file)
3376+
33743377
if rl_type != RlType.NONE:
33753378
readline.clear_history()
3376-
if self.persistent_history_file:
3377-
os.remove(self.persistent_history_file)
33783379
return
33793380

33803381
# If an argument was supplied, then retrieve partial contents of the history
@@ -3468,7 +3469,7 @@ def _initialize_history(self, hist_file):
34683469
self.persistent_history_file = hist_file
34693470
return
34703471

3471-
hist_file = os.path.expanduser(hist_file)
3472+
hist_file = os.path.abspath(os.path.expanduser(hist_file))
34723473

34733474
# first we try and unpickle the history file
34743475
history = History()
@@ -3690,7 +3691,7 @@ def do_load(self, args: argparse.Namespace) -> None:
36903691
return
36913692

36923693
if args.transcript:
3693-
self._generate_transcript(script_commands, os.path.expanduser(args.transcript))
3694+
self._generate_transcript(script_commands, args.transcript)
36943695
return
36953696

36963697
self.cmdqueue = script_commands + ['eos'] + self.cmdqueue

0 commit comments

Comments
 (0)