aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-03-24 12:17:25 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2022-06-26 18:05:50 +0200
commit7d1c7d8337853ca99e6ec1150ac4b834cfed5cd3 (patch)
tree6fd6c647b5373ed376070d66ac6ca4acc507dee7 /libbb
parent95fec31be601bfdced6bed7007a33b26e968e0db (diff)
downloadbusybox-w32-7d1c7d8337853ca99e6ec1150ac4b834cfed5cd3.tar.gz
busybox-w32-7d1c7d8337853ca99e6ec1150ac4b834cfed5cd3.tar.bz2
busybox-w32-7d1c7d8337853ca99e6ec1150ac4b834cfed5cd3.zip
ash,hush: use HOME for tab completion and prompts
ash and hush correctly use the value of HOME for tilde expansion. However the line editing code in libbb obtains the user's home directory by calling getpwuid(). Thus tildes in tab completion and prompts may be interpreted differently than in tilde expansion. When the line editing code is invoked from a shell make it use the shell's interpretation of tilde. This is similar to how GNU readline and bash collaborate. function old new delta get_homedir_or_NULL 29 72 +43 optschanged 119 126 +7 hush_main 1204 1211 +7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 57/0) Total: 57 bytes v2: Always check for HOME before trying the password database: this is what GNU readline does. Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 82624757e..b685399f9 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -259,6 +259,16 @@ static const char *get_username_str(void)
259 259
260static NOINLINE const char *get_homedir_or_NULL(void) 260static NOINLINE const char *get_homedir_or_NULL(void)
261{ 261{
262 const char *home;
263
264# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH
265 home = state->sh_get_var ? state->sh_get_var("HOME") : getenv("HOME");
266# else
267 home = getenv("HOME");
268# endif
269 if (home != NULL && home[0] != '\0')
270 return home;
271
262 if (!got_user_strings) 272 if (!got_user_strings)
263 get_user_strings(); 273 get_user_strings();
264 return home_pwd_buf; 274 return home_pwd_buf;
@@ -861,7 +871,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
861 continue; 871 continue;
862 } 872 }
863# endif 873# endif
864# if EDITING_HAS_get_exe_name 874# if ENABLE_SHELL_ASH || ENABLE_SHELL_HUSH
865 if (state->get_exe_name) { 875 if (state->get_exe_name) {
866 i = 0; 876 i = 0;
867 for (;;) { 877 for (;;) {