From 3a6c1a9898ce7535f41e876b4a733cf31281d24d Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Tue, 12 Nov 2024 11:58:23 +0000 Subject: [PATCH 1/5] Add fixes for target-shell prompt And some miscellaneous fixes of typing and consistency --- dissect/target/tools/shell.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/dissect/target/tools/shell.py b/dissect/target/tools/shell.py index a3d9a83177..9aacd4bc40 100644 --- a/dissect/target/tools/shell.py +++ b/dissect/target/tools/shell.py @@ -21,9 +21,9 @@ from datetime import datetime, timedelta, timezone from typing import Any, BinaryIO, Callable, Iterator, TextIO -from dissect.cstruct import hexdump from flow.record import RecordOutput +from dissect.cstruct import hexdump from dissect.target.exceptions import ( PluginError, RegistryError, @@ -304,11 +304,11 @@ def _exec_(argparts: list[str], stdout: TextIO) -> bool: no_cyber = cmdfunc.__func__ in (TargetCli.cmd_registry, TargetCli.cmd_enter) return self._exec(_exec_, command_args_str, no_cyber) - def do_man(self, line: str) -> bool: + def do_man(self, line: str) -> None: """alias for help""" - return self.do_help(line) + self.do_help(line) - def complete_man(self, *args) -> list[str]: + def complete_man(self, *args: list[str]) -> list[str]: return cmd.Cmd.complete_help(self, *args) def do_unalias(self, line: str) -> bool: @@ -403,6 +403,7 @@ def __init__(self, target: Target): self.histfile = pathlib.Path(getattr(target._config, "HISTFILE", self.DEFAULT_HISTFILE)).expanduser() # prompt format + self.prompt_ps1 = "{BOLD_GREEN}{base}{RESET}:{BOLD_BLUE}{cwd}{RESET}$ " if ps1 := getattr(target._config, "PS1", None): if "{cwd}" in ps1 and "{base}" in ps1: self.prompt_ps1 = ps1 @@ -410,9 +411,6 @@ def __init__(self, target: Target): elif getattr(target._config, "NO_COLOR", None) or os.getenv("NO_COLOR"): self.prompt_ps1 = "{base}:{cwd}$ " - else: - self.prompt_ps1 = "{BOLD_GREEN}{base}{RESET}:{BOLD_BLUE}{cwd}{RESET}$ " - super().__init__(self.target.props.get("cyber")) def _get_targetrc_path(self) -> pathlib.Path: From cdfc10a5ef49303b8d570341a8b75a29862f8dca Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Tue, 12 Nov 2024 13:07:03 +0000 Subject: [PATCH 2/5] Add warning when prompt does not contain cwd and base --- dissect/target/tools/shell.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dissect/target/tools/shell.py b/dissect/target/tools/shell.py index 9aacd4bc40..0b4a8dfa5b 100644 --- a/dissect/target/tools/shell.py +++ b/dissect/target/tools/shell.py @@ -407,6 +407,8 @@ def __init__(self, target: Target): if ps1 := getattr(target._config, "PS1", None): if "{cwd}" in ps1 and "{base}" in ps1: self.prompt_ps1 = ps1 + else: + self.target.log.warning("Error {cwd} and {base} was not set inside PS1, using the default prompt.") elif getattr(target._config, "NO_COLOR", None) or os.getenv("NO_COLOR"): self.prompt_ps1 = "{base}:{cwd}$ " From 00b88a195b5bbfbdbf16b26fdce0aa938b36a639 Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Tue, 12 Nov 2024 13:45:18 +0000 Subject: [PATCH 3/5] Made do_man consistent with other do_ functions --- dissect/target/tools/shell.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dissect/target/tools/shell.py b/dissect/target/tools/shell.py index 0b4a8dfa5b..e74483a6c6 100644 --- a/dissect/target/tools/shell.py +++ b/dissect/target/tools/shell.py @@ -304,9 +304,10 @@ def _exec_(argparts: list[str], stdout: TextIO) -> bool: no_cyber = cmdfunc.__func__ in (TargetCli.cmd_registry, TargetCli.cmd_enter) return self._exec(_exec_, command_args_str, no_cyber) - def do_man(self, line: str) -> None: + def do_man(self, line: str) -> bool: """alias for help""" self.do_help(line) + return False def complete_man(self, *args: list[str]) -> list[str]: return cmd.Cmd.complete_help(self, *args) From 02dd8a10a3d77176dcca0b5ee4e9b355e5c52e31 Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Tue, 12 Nov 2024 15:14:52 +0100 Subject: [PATCH 4/5] Update dissect/target/tools/shell.py Co-authored-by: Erik Schamper <1254028+Schamper@users.noreply.github.com> --- dissect/target/tools/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dissect/target/tools/shell.py b/dissect/target/tools/shell.py index e74483a6c6..7ce19a7909 100644 --- a/dissect/target/tools/shell.py +++ b/dissect/target/tools/shell.py @@ -409,7 +409,7 @@ def __init__(self, target: Target): if "{cwd}" in ps1 and "{base}" in ps1: self.prompt_ps1 = ps1 else: - self.target.log.warning("Error {cwd} and {base} was not set inside PS1, using the default prompt.") + self.target.log.warning("{cwd} and {base} were not set inside PS1, using the default prompt") elif getattr(target._config, "NO_COLOR", None) or os.getenv("NO_COLOR"): self.prompt_ps1 = "{base}:{cwd}$ " From 2a93fe1812b769ba72c37e10dad8b06eaf61bff6 Mon Sep 17 00:00:00 2001 From: Miauwkeru Date: Wed, 2 Apr 2025 12:26:18 +0000 Subject: [PATCH 5/5] Fix import sort --- dissect/target/tools/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dissect/target/tools/shell.py b/dissect/target/tools/shell.py index 7ce19a7909..eb0dc4006b 100644 --- a/dissect/target/tools/shell.py +++ b/dissect/target/tools/shell.py @@ -21,9 +21,9 @@ from datetime import datetime, timedelta, timezone from typing import Any, BinaryIO, Callable, Iterator, TextIO +from dissect.cstruct import hexdump from flow.record import RecordOutput -from dissect.cstruct import hexdump from dissect.target.exceptions import ( PluginError, RegistryError,