Closed yf13 closed 5 months ago
but you can set CONFIG_NSH_PROMPT_STRING to different string in each defconfig.
@xiaoxiang781216 using NSH_PROMPT_STRING config can't solve the issue as the master and remote node shares the same NSH binary, thus both master and remote consoles show the same prompt string, this confuses NSH console users.
@xiaoxiang781216 using NSH_PROMPT_STRING config can't solve the issue as the master and remote node shares the same NSH binary, thus both master and remote consoles show the same prompt string.
If so, let's use the approach like bash: https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
@xiaoxiang781216 did you mean that NSH already supports special variables PS1
? I tried using set PS1 aaa
in NSH session, I can see PS1=aaa
via env
command, but the prompt string doesn't change at all. Did I miss anything?
Or did you mean that we should add PS1 alike feature to NSH? that may need more time/effort as I am still unfamilar with NSH.
@xiaoxiang781216 did you mean that NSH already supports special variables
PS1
? I tried usingset PS1 aaa
in NSH session, I can seePS1=aaa
viaenv
command, but the prompt string doesn't change at all. Did I miss anything?
NSH doesn't support PS1 yet.
Or did you mean that we should add PS1 alike feature to NSH? that may need more time/effort as I am still unfamilar with NSH.
it's simple, something like this:
FAR const char *nsh_getprompt(void)
{
FAR const char *ps1 = getenv("PS1");
return ps1 ? ps1 : g_nshprompt;
}
@xiaoxiang781216 we may need check how readline works. it has an internal reference of g_nshprompt.
@xiaoxiang781216 please see if this version works or not? it has PS1 support.
Summary
Currently NSH prompt string is determined at build time, this is inflexible in some AMP cases where the same NSH binary runs on different AMP nodes as the same prompt string is showed everywhere. Yet another issue is that empty
NSH_RPOMPT_STRING
config leads to no prompt at all, making people questioning if the system is stalled.This patch attempts to solve these issues by adding ordered runtime fallbacks for empty NSH_PROMPT_STRING case from sources like environment variable (default to
PS1
) and hostname, both suffixed with>
. If all sources are empty, the non-empty suffix string will be used. The patch has little impacts on for existing use cases with non-empty NSH_PROMPT_STRING .Changes in nshlib/ folder:
New additions in
nshlib/
Impact
NSH app
Testing
Checked with CanMV230
Limits
All sources are plaintext, there is no shell escaping, terminfo escaping, command embedding etc.