* [PATCH] hush: implement PROMPT_COMMAND
@ 2025-08-06 13:16 Ahmad Fatoum
2025-08-13 5:49 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-08-06 13:16 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
This allows dynamically updating the prompt to reflect new contextual or
global information (e.g. which security mode barebox is in).
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
common/Kconfig | 1 +
common/hush.c | 12 +++++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/common/Kconfig b/common/Kconfig
index b2449207eff9..1d9570ef67b5 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -515,6 +515,7 @@ config HUSH_FANCY_PROMPT
help
Allow to set PS1 from the command line. PS1 can have several escaped commands
like \h for the 'model' string or \w for the current working directory.
+ PS1 can be set statically or computed on demand by executing PROMPT_COMMAND.
config CMDLINE_EDITING
depends on !SHELL_NONE
diff --git a/common/hush.c b/common/hush.c
index 086cbc68b891..552e7327de92 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -426,8 +426,17 @@ static char *getprompt(void)
static char prompt[PATH_MAX + 32];
#ifdef CONFIG_HUSH_FANCY_PROMPT
- const char *ps1 = getenv("PS1");
+ const char *ps1, *prompt_command;
+ struct p_context ctx = {};
+ prompt_command = getenv("PROMPT_COMMAND");
+ if (prompt_command) {
+ initialize_context(&ctx);
+ parse_string_outer(&ctx, prompt_command, FLAG_PARSE_SEMICOLON);
+ release_context(&ctx);
+ }
+
+ ps1 = getenv("PS1");
if (ps1)
process_escape_sequence(ps1, prompt, PATH_MAX + 32);
else
@@ -2065,6 +2074,7 @@ BAREBOX_CMD_END
BAREBOX_MAGICVAR(PATH, "colon separated list of paths to search for executables");
#ifdef CONFIG_HUSH_FANCY_PROMPT
BAREBOX_MAGICVAR(PS1, "hush prompt");
+BAREBOX_MAGICVAR(PROMPT_COMMAND, "command to execute prior to each primary prompt");
#endif
static int binfmt_sh_excute(struct binfmt_hook *b, char *file, int argc, char **argv)
--
2.39.5
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-13 6:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-06 13:16 [PATCH] hush: implement PROMPT_COMMAND Ahmad Fatoum
2025-08-13 5:49 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox