diff options
author | Ron Yorston <rmy@pobox.com> | 2022-03-24 11:43:37 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-03-24 12:26:01 +0000 |
commit | 3e385d22cc57aacddafe38a1b6bcd55aa71d3c80 (patch) | |
tree | 8c8ac54290ec6010d76206c5bd0e47f92bf2b13f /shell | |
parent | af41de68901d48753eb73491d54931a99d1a13b5 (diff) | |
download | busybox-w32-tilde.tar.gz busybox-w32-tilde.tar.bz2 busybox-w32-tilde.zip |
ash,hush: use HOME for tab completion and promptstilde
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>
Diffstat (limited to '')
-rw-r--r-- | shell/ash.c | 7 | ||||
-rw-r--r-- | shell/hush.c | 5 |
2 files changed, 5 insertions, 7 deletions
diff --git a/shell/ash.c b/shell/ash.c index e8a1e853c..dd806b629 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -10554,7 +10554,7 @@ evalpipe(union node *n, int flags) | |||
10554 | } | 10554 | } |
10555 | 10555 | ||
10556 | /* setinteractive needs this forward reference */ | 10556 | /* setinteractive needs this forward reference */ |
10557 | #if EDITING_HAS_get_exe_name | 10557 | #if ENABLE_FEATURE_EDITING |
10558 | static const char *get_builtin_name(int i) FAST_FUNC; | 10558 | static const char *get_builtin_name(int i) FAST_FUNC; |
10559 | #endif | 10559 | #endif |
10560 | 10560 | ||
@@ -10591,9 +10591,8 @@ setinteractive(int on) | |||
10591 | #if ENABLE_FEATURE_EDITING | 10591 | #if ENABLE_FEATURE_EDITING |
10592 | if (!line_input_state) { | 10592 | if (!line_input_state) { |
10593 | line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); | 10593 | line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); |
10594 | # if EDITING_HAS_get_exe_name | ||
10595 | line_input_state->get_exe_name = get_builtin_name; | 10594 | line_input_state->get_exe_name = get_builtin_name; |
10596 | # endif | 10595 | line_input_state->sh_get_var = lookupvar; |
10597 | } | 10596 | } |
10598 | #endif | 10597 | #endif |
10599 | } | 10598 | } |
@@ -11096,7 +11095,7 @@ find_builtin(const char *name) | |||
11096 | return bp; | 11095 | return bp; |
11097 | } | 11096 | } |
11098 | 11097 | ||
11099 | #if EDITING_HAS_get_exe_name | 11098 | #if ENABLE_FEATURE_EDITING |
11100 | static const char * FAST_FUNC | 11099 | static const char * FAST_FUNC |
11101 | get_builtin_name(int i) | 11100 | get_builtin_name(int i) |
11102 | { | 11101 | { |
diff --git a/shell/hush.c b/shell/hush.c index ae81f0da5..051b123e7 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -8188,7 +8188,7 @@ static const struct built_in_command *find_builtin(const char *name) | |||
8188 | return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]); | 8188 | return find_builtin_helper(name, bltins2, &bltins2[ARRAY_SIZE(bltins2)]); |
8189 | } | 8189 | } |
8190 | 8190 | ||
8191 | #if ENABLE_HUSH_JOB && EDITING_HAS_get_exe_name | 8191 | #if ENABLE_HUSH_JOB && ENABLE_FEATURE_EDITING |
8192 | static const char * FAST_FUNC get_builtin_name(int i) | 8192 | static const char * FAST_FUNC get_builtin_name(int i) |
8193 | { | 8193 | { |
8194 | if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { | 8194 | if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { |
@@ -10668,9 +10668,8 @@ int hush_main(int argc, char **argv) | |||
10668 | 10668 | ||
10669 | # if ENABLE_FEATURE_EDITING | 10669 | # if ENABLE_FEATURE_EDITING |
10670 | G.line_input_state = new_line_input_t(FOR_SHELL); | 10670 | G.line_input_state = new_line_input_t(FOR_SHELL); |
10671 | # if EDITING_HAS_get_exe_name | ||
10672 | G.line_input_state->get_exe_name = get_builtin_name; | 10671 | G.line_input_state->get_exe_name = get_builtin_name; |
10673 | # endif | 10672 | G.line_input_state->sh_get_var = get_local_var_value; |
10674 | # endif | 10673 | # endif |
10675 | # if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 | 10674 | # if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 |
10676 | { | 10675 | { |