Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixes for target-shell prompt #943

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions dissect/target/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,10 @@

def do_man(self, line: str) -> bool:
"""alias for help"""
return self.do_help(line)
self.do_help(line)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc all Cmd functions should explicitly return a boolean value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting, perhaps do_help is exempted from this.

Copy link
Member

@Schamper Schamper Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we decided that everything should be consistent in returning booleans across the board in the refactor.

The standard library isn't, but we are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I'll just return a True in that function and be done with it

return False

Check warning on line 259 in dissect/target/tools/shell.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/tools/shell.py#L258-L259

Added lines #L258 - L259 were not covered by tests

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:
Expand Down Expand Up @@ -352,16 +353,16 @@
self.histfile = pathlib.Path(getattr(target._config, "HISTFILE", self.DEFAULT_HISTFILE)).expanduser()

# prompt format
self.prompt_ps1 = "\x1b[1;32m{base}\x1b[0m:\x1b[1;34m{cwd}\x1b[0m$ "
if ps1 := getattr(target._config, "PS1", None):
if "{cwd}" in ps1 and "{base}" in ps1:
self.prompt_ps1 = ps1
else:
self.target.log.warning("{cwd} and {base} were not set inside PS1, using the default prompt")

Check warning on line 361 in dissect/target/tools/shell.py

View check run for this annotation

Codecov / codecov/patch

dissect/target/tools/shell.py#L361

Added line #L361 was not covered by tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there should be an else here to warn the user of an incomplete PS1 config value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good idea, I'll add that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it at L360

elif getattr(target._config, "NO_COLOR", None) or os.getenv("NO_COLOR"):
self.prompt_ps1 = "{base}:{cwd}$ "

else:
self.prompt_ps1 = "\x1b[1;32m{base}\x1b[0m:\x1b[1;34m{cwd}\x1b[0m$ "

super().__init__(self.target.props.get("cyber"))

def _get_targetrc_path(self) -> pathlib.Path:
Expand Down
Loading