-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,9 +255,10 @@ | |
|
||
def do_man(self, line: str) -> bool: | ||
"""alias for help""" | ||
return self.do_help(line) | ||
self.do_help(line) | ||
return False | ||
|
||
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: | ||
|
@@ -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") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps there should be an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is a good idea, I'll add that There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the
do_help
ofCmd
doesn't return any value: https://github.com/python/cpython/blob/fb0b642bf1aa3ec276304b7170deedd5040c1698/Lib/cmd.py#L292There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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