Skip to content

Commit

Permalink
Merge pull request #23 from adinhodovic/fix-shell-saving
Browse files Browse the repository at this point in the history
fix: Regex patterns for terminal prompts
  • Loading branch information
adinhodovic committed Feb 29, 2024
2 parents bde8d50 + 13d792c commit 54e7b93
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,5 @@ daphne config.asgi:application -b 127.0.0.1 -p 8001
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| DJANGO_ADMIN_SHELLX_SUPERUSER_ONLY | Allow only SuperUsers to access the admin shellx. | `boolean` | `True` | no |
| DJANGO_ADMIN_SHELLX_COMMAND | The default commands to use when opening the terminal. | `list[list[str]]` | [["./manage.py", "shell_plus"], ["./manage.py", "shell"], ["/bin/bash"]] | no |
| DJANGO_ADMIN_SHELLX_COMMANDS | The default commands to use when opening the terminal. | `list[list[str]]` | [["./manage.py", "shell_plus"], ["./manage.py", "shell"], ["/bin/bash"]] | no |
| DJANGO_ADMIN_SHELLX_WS_PORT | The port to use for the websocket. | `int` | None | no |
8 changes: 7 additions & 1 deletion django_admin_shellx/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,16 @@ def disconnect(self, code):

def map_terminal_prompt(self, terminal_prompt):

if "reverse-i-search" in terminal_prompt or "I-search" in terminal_prompt:
return "DJWShell Search", None

command = None
prompt = None

# pattern >>> TerminalCommand.objects.all()
match_1 = re.match(r">>> (.*)", terminal_prompt)
# pattern In [2]: TerminalCommand.objects.all()'
match_2 = re.match(r"In \[\w\]: (.*)", terminal_prompt)
match_2 = re.match(r"In \[.*\]: (.*)", terminal_prompt)
# pattern root@test-app-bf4fdfb6-726qh:/app# echo 'hello world'
match_3 = re.match(r"^(\S+\s+[^$]+\$)\s+(.*)", terminal_prompt)
# [adin@adin test]$ echo 'hello world'
Expand Down Expand Up @@ -170,6 +173,9 @@ def map_terminal_prompt(self, terminal_prompt):
def save_command_history(self, command):
command, prompt = self.map_terminal_prompt(command)

if command == "DJWShell Search":
return

if not command:
logging.warning("No command to save")
return
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "django-admin-shellx"
version = "0.2.2"
version = "0.2.3"
description = "A Django Admin Shell"
authors = ["Adin Hodovic <hodovicadin@gmail.com>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

DJANGO_ADMIN_SHELLX_SUPERUSER_ONLY = True
DJANGO_ADMIN_SHELLX_COMMAND = [
DJANGO_ADMIN_SHELLX_COMMANDS = [
["./manage.py", "shell_plus"],
["./manage.py", "shell"],
["/bin/bash"],
Expand Down

0 comments on commit 54e7b93

Please sign in to comment.