diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-04-24 06:26:18 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2009-04-24 06:26:18 +0000 |
commit | 67c1c7b456f18fe397ab0dfad92f13b5080b0c52 (patch) | |
tree | 6eba76c785aea835a7b070729fea630b894e4d90 | |
parent | eb4e5ecc321cdb2bcfabf0f94c40bdb9690b48f4 (diff) | |
download | busybox-w32-67c1c7b456f18fe397ab0dfad92f13b5080b0c52.tar.gz busybox-w32-67c1c7b456f18fe397ab0dfad92f13b5080b0c52.tar.bz2 busybox-w32-67c1c7b456f18fe397ab0dfad92f13b5080b0c52.zip |
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
-rw-r--r-- | shell/hush.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/shell/hush.c b/shell/hush.c index 56b12cebc..924d826cc 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -795,6 +795,13 @@ static void syntax_error_unexpected_ch(unsigned lineno, char ch) | |||
795 | #endif | 795 | #endif |
796 | 796 | ||
797 | 797 | ||
798 | #if ENABLE_HUSH_INTERACTIVE | ||
799 | static void cmdedit_update_prompt(void); | ||
800 | #else | ||
801 | # define cmdedit_update_prompt() | ||
802 | #endif | ||
803 | |||
804 | |||
798 | /* Utility functions | 805 | /* Utility functions |
799 | */ | 806 | */ |
800 | static int glob_needed(const char *s) | 807 | 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) | |||
1332 | exp: | 1339 | exp: |
1333 | if (flg_export == 1) | 1340 | if (flg_export == 1) |
1334 | cur->flg_export = 1; | 1341 | cur->flg_export = 1; |
1342 | if (name_len == 4 && cur->varstr[0] == 'P' && cur->varstr[1] == 'S') | ||
1343 | cmdedit_update_prompt(); | ||
1335 | if (cur->flg_export) { | 1344 | if (cur->flg_export) { |
1336 | if (flg_export == -1) { | 1345 | if (flg_export == -1) { |
1337 | cur->flg_export = 0; | 1346 | cur->flg_export = 0; |
@@ -1365,6 +1374,8 @@ static int unset_local_var(const char *name) | |||
1365 | prev->next = cur->next; | 1374 | prev->next = cur->next; |
1366 | debug_printf_env("%s: unsetenv '%s'\n", __func__, cur->varstr); | 1375 | debug_printf_env("%s: unsetenv '%s'\n", __func__, cur->varstr); |
1367 | bb_unsetenv(cur->varstr); | 1376 | bb_unsetenv(cur->varstr); |
1377 | if (name_len == 3 && cur->varstr[0] == 'P' && cur->varstr[1] == 'S') | ||
1378 | cmdedit_update_prompt(); | ||
1368 | if (!cur->max_len) | 1379 | if (!cur->max_len) |
1369 | free(cur->varstr); | 1380 | free(cur->varstr); |
1370 | free(cur); | 1381 | free(cur); |
@@ -1421,14 +1432,17 @@ static int static_peek(struct in_str *i) | |||
1421 | 1432 | ||
1422 | #if ENABLE_HUSH_INTERACTIVE | 1433 | #if ENABLE_HUSH_INTERACTIVE |
1423 | 1434 | ||
1424 | static void cmdedit_set_initial_prompt(void) | 1435 | static void cmdedit_update_prompt(void) |
1425 | { | 1436 | { |
1426 | if (ENABLE_FEATURE_EDITING_FANCY_PROMPT) { | 1437 | if (ENABLE_FEATURE_EDITING_FANCY_PROMPT) { |
1427 | G.PS1 = getenv("PS1"); | 1438 | G.PS1 = get_local_var_value("PS1"); |
1428 | if (G.PS1 == NULL) | 1439 | if (G.PS1 == NULL) |
1429 | G.PS1 = "\\w \\$ "; | 1440 | G.PS1 = "\\w \\$ "; |
1441 | G.PS2 = get_local_var_value("PS2"); | ||
1430 | } else | 1442 | } else |
1431 | G.PS1 = NULL; | 1443 | G.PS1 = NULL; |
1444 | if (G.PS2 == NULL) | ||
1445 | G.PS2 = "> "; | ||
1432 | } | 1446 | } |
1433 | 1447 | ||
1434 | static const char* setup_prompt_string(int promptmode) | 1448 | static const char* setup_prompt_string(int promptmode) |
@@ -6002,11 +6016,7 @@ int hush_main(int argc, char **argv) | |||
6002 | G.global_argv = argv; | 6016 | G.global_argv = argv; |
6003 | /* Initialize some more globals to non-zero values */ | 6017 | /* Initialize some more globals to non-zero values */ |
6004 | set_cwd(); | 6018 | set_cwd(); |
6005 | #if ENABLE_HUSH_INTERACTIVE | 6019 | cmdedit_update_prompt(); |
6006 | if (ENABLE_FEATURE_EDITING) | ||
6007 | cmdedit_set_initial_prompt(); | ||
6008 | G.PS2 = "> "; | ||
6009 | #endif | ||
6010 | 6020 | ||
6011 | if (setjmp(die_jmp)) { | 6021 | if (setjmp(die_jmp)) { |
6012 | /* xfunc has failed! die die die */ | 6022 | /* xfunc has failed! die die die */ |
@@ -6334,7 +6344,7 @@ static int builtin_cd(char **argv) | |||
6334 | * bash says "bash: cd: HOME not set" and does nothing | 6344 | * bash says "bash: cd: HOME not set" and does nothing |
6335 | * (exitcode 1) | 6345 | * (exitcode 1) |
6336 | */ | 6346 | */ |
6337 | newdir = getenv("HOME") ? : "/"; | 6347 | newdir = get_local_var_value("HOME") ? : "/"; |
6338 | } | 6348 | } |
6339 | if (chdir(newdir)) { | 6349 | if (chdir(newdir)) { |
6340 | /* Mimic bash message exactly */ | 6350 | /* Mimic bash message exactly */ |