mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
use get_local_var_value() rather than getenv() when working with PS1/PS2/HOME, respect the PS2 env var, and make sure that the prompt changes whenever PS1/PS2 changes so we dont have to re-exec the shell to get a changed prompt
This commit is contained in:
parent
eb4e5ecc32
commit
67c1c7b456
26
shell/hush.c
26
shell/hush.c
@ -795,6 +795,13 @@ static void syntax_error_unexpected_ch(unsigned lineno, char ch)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if ENABLE_HUSH_INTERACTIVE
|
||||||
|
static void cmdedit_update_prompt(void);
|
||||||
|
#else
|
||||||
|
# define cmdedit_update_prompt()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Utility functions
|
/* Utility functions
|
||||||
*/
|
*/
|
||||||
static int glob_needed(const char *s)
|
static int glob_needed(const char *s)
|
||||||
@ -1332,6 +1339,8 @@ static int set_local_var(char *str, int flg_export, int flg_read_only)
|
|||||||
exp:
|
exp:
|
||||||
if (flg_export == 1)
|
if (flg_export == 1)
|
||||||
cur->flg_export = 1;
|
cur->flg_export = 1;
|
||||||
|
if (name_len == 4 && cur->varstr[0] == 'P' && cur->varstr[1] == 'S')
|
||||||
|
cmdedit_update_prompt();
|
||||||
if (cur->flg_export) {
|
if (cur->flg_export) {
|
||||||
if (flg_export == -1) {
|
if (flg_export == -1) {
|
||||||
cur->flg_export = 0;
|
cur->flg_export = 0;
|
||||||
@ -1365,6 +1374,8 @@ static int unset_local_var(const char *name)
|
|||||||
prev->next = cur->next;
|
prev->next = cur->next;
|
||||||
debug_printf_env("%s: unsetenv '%s'\n", __func__, cur->varstr);
|
debug_printf_env("%s: unsetenv '%s'\n", __func__, cur->varstr);
|
||||||
bb_unsetenv(cur->varstr);
|
bb_unsetenv(cur->varstr);
|
||||||
|
if (name_len == 3 && cur->varstr[0] == 'P' && cur->varstr[1] == 'S')
|
||||||
|
cmdedit_update_prompt();
|
||||||
if (!cur->max_len)
|
if (!cur->max_len)
|
||||||
free(cur->varstr);
|
free(cur->varstr);
|
||||||
free(cur);
|
free(cur);
|
||||||
@ -1421,14 +1432,17 @@ static int static_peek(struct in_str *i)
|
|||||||
|
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
#if ENABLE_HUSH_INTERACTIVE
|
||||||
|
|
||||||
static void cmdedit_set_initial_prompt(void)
|
static void cmdedit_update_prompt(void)
|
||||||
{
|
{
|
||||||
if (ENABLE_FEATURE_EDITING_FANCY_PROMPT) {
|
if (ENABLE_FEATURE_EDITING_FANCY_PROMPT) {
|
||||||
G.PS1 = getenv("PS1");
|
G.PS1 = get_local_var_value("PS1");
|
||||||
if (G.PS1 == NULL)
|
if (G.PS1 == NULL)
|
||||||
G.PS1 = "\\w \\$ ";
|
G.PS1 = "\\w \\$ ";
|
||||||
|
G.PS2 = get_local_var_value("PS2");
|
||||||
} else
|
} else
|
||||||
G.PS1 = NULL;
|
G.PS1 = NULL;
|
||||||
|
if (G.PS2 == NULL)
|
||||||
|
G.PS2 = "> ";
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* setup_prompt_string(int promptmode)
|
static const char* setup_prompt_string(int promptmode)
|
||||||
@ -6002,11 +6016,7 @@ int hush_main(int argc, char **argv)
|
|||||||
G.global_argv = argv;
|
G.global_argv = argv;
|
||||||
/* Initialize some more globals to non-zero values */
|
/* Initialize some more globals to non-zero values */
|
||||||
set_cwd();
|
set_cwd();
|
||||||
#if ENABLE_HUSH_INTERACTIVE
|
cmdedit_update_prompt();
|
||||||
if (ENABLE_FEATURE_EDITING)
|
|
||||||
cmdedit_set_initial_prompt();
|
|
||||||
G.PS2 = "> ";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (setjmp(die_jmp)) {
|
if (setjmp(die_jmp)) {
|
||||||
/* xfunc has failed! die die die */
|
/* xfunc has failed! die die die */
|
||||||
@ -6334,7 +6344,7 @@ static int builtin_cd(char **argv)
|
|||||||
* bash says "bash: cd: HOME not set" and does nothing
|
* bash says "bash: cd: HOME not set" and does nothing
|
||||||
* (exitcode 1)
|
* (exitcode 1)
|
||||||
*/
|
*/
|
||||||
newdir = getenv("HOME") ? : "/";
|
newdir = get_local_var_value("HOME") ? : "/";
|
||||||
}
|
}
|
||||||
if (chdir(newdir)) {
|
if (chdir(newdir)) {
|
||||||
/* Mimic bash message exactly */
|
/* Mimic bash message exactly */
|
||||||
|
Loading…
Reference in New Issue
Block a user