summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/Kconfig9
-rw-r--r--common/hush.c12
2 files changed, 17 insertions, 4 deletions
diff --git a/common/Kconfig b/common/Kconfig
index 4c4a627a36..f5147597f4 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -226,6 +226,15 @@ config PROMPT_HUSH_PS2
prompt "hush PS2"
default "> "
+config HUSH_FANCY_PROMPT
+ bool
+ depends on SHELL_HUSH
+ select PROCESS_ESCAPE_SEQUENCE
+ prompt "allow fancy hush prompts"
+ help
+ Allow to set PS1 from the command line. PS1 can have several escaped commands
+ like \h for CONFIG_BOARDINFO or \w for the current working directory.
+
config CMDLINE_EDITING
bool
prompt "Enable command line editing"
diff --git a/common/hush.c b/common/hush.c
index afa67d16f5..19e35f5fa1 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -389,15 +389,19 @@ static int static_peek(struct in_str *i)
return *i->p;
}
-
static char *getprompt(void)
{
- static char *prompt;
+ static char prompt[PATH_MAX + 32];
- if (!prompt)
- prompt = xmalloc(PATH_MAX + strlen(CONFIG_PROMPT) + 1);
+#ifdef CONFIG_HUSH_FANCY_PROMPT
+ const char *ps1 = getenv("PS1");
+ if (ps1)
+ process_escape_sequence(ps1, prompt, PATH_MAX + 32);
+ else
+#endif
sprintf(prompt, "%s%s ", CONFIG_PROMPT, getcwd());
+
return prompt;
}