Skip to content

Commit

Permalink
feat: Add support for executing previous commands in sqlite3-cli-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Simatwa committed Nov 8, 2024
1 parent aabaaca commit 94cc161
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ class Interactive(cmd.Cmd):
intro = (
"Welcome to interactive sqlite3-db manager.\n"
"Run help or h <command> for usage info.\n"
"Use '!' to execute previous commands.\n"
"Repository : https://github.com/Simatwa/sqlite3-cli-manager"
)
__init_time = time.time()
Expand Down Expand Up @@ -424,14 +425,14 @@ def default(self, line: str, prompt_confirmation: bool = False, ai_generated=Fal
if line.startswith("./"):
self.do_sys(line[2:])
return

# self.onecmd
elif line.startswith("!"):
# Let's try to mimic the unix' previous command(s) execution shortcut
history = self.completer_session.history.get_strings()
command_number = line.count("!")
if len(history) >= command_number:
line = [history[-command_number - 1]]
prompt_confirmation = True
line = history[-command_number - 1]
return self.onecmd(line)
else:
click.secho("Index out of range!", fg="yellow")
return
Expand Down

0 comments on commit 94cc161

Please sign in to comment.