diff options
author | Ron Yorston <rmy@pobox.com> | 2023-04-13 12:56:14 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-04-16 17:15:05 +0200 |
commit | acae889dd97280ee59b7e04c18005bb8875cb0d2 (patch) | |
tree | dcde9a9d1c328443b03e4004101b471d39f7fd6f /shell/ash.c | |
parent | 90b607d79a1377d6a5dda44ee112698c58432203 (diff) | |
download | busybox-w32-acae889dd97280ee59b7e04c18005bb8875cb0d2.tar.gz busybox-w32-acae889dd97280ee59b7e04c18005bb8875cb0d2.tar.bz2 busybox-w32-acae889dd97280ee59b7e04c18005bb8875cb0d2.zip |
ash,hush: tab completion of functions and aliases
Since commit 9e2a5668f (ash,hush: allow builtins to be tab-completed,
closes 7532) ash and hush have supported tab completion of builtins.
Other shells, bash and ksh for example, also support tab completion
of functions and aliases.
Add such support to ash and hush.
function old new delta
ash_command_name - 92 +92
hush_command_name - 63 +63
ash_builtin_name 17 - -17
hush_builtin_name 38 - -38
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55) Total: 100 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash.c')
-rw-r--r-- | shell/ash.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/shell/ash.c b/shell/ash.c index d4ee4c93e..d2c5c5d50 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -9732,7 +9732,7 @@ evalpipe(union node *n, int flags) | |||
9732 | 9732 | ||
9733 | /* setinteractive needs this forward reference */ | 9733 | /* setinteractive needs this forward reference */ |
9734 | #if ENABLE_FEATURE_TAB_COMPLETION | 9734 | #if ENABLE_FEATURE_TAB_COMPLETION |
9735 | static const char *get_builtin_name(int i) FAST_FUNC; | 9735 | static const char *ash_command_name(int i) FAST_FUNC; |
9736 | #endif | 9736 | #endif |
9737 | 9737 | ||
9738 | /* | 9738 | /* |
@@ -9769,7 +9769,7 @@ setinteractive(int on) | |||
9769 | if (!line_input_state) { | 9769 | if (!line_input_state) { |
9770 | line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); | 9770 | line_input_state = new_line_input_t(FOR_SHELL | WITH_PATH_LOOKUP); |
9771 | # if ENABLE_FEATURE_TAB_COMPLETION | 9771 | # if ENABLE_FEATURE_TAB_COMPLETION |
9772 | line_input_state->get_exe_name = get_builtin_name; | 9772 | line_input_state->get_exe_name = ash_command_name; |
9773 | # endif | 9773 | # endif |
9774 | # if EDITING_HAS_sh_get_var | 9774 | # if EDITING_HAS_sh_get_var |
9775 | line_input_state->sh_get_var = lookupvar; | 9775 | line_input_state->sh_get_var = lookupvar; |
@@ -10284,9 +10284,33 @@ find_builtin(const char *name) | |||
10284 | 10284 | ||
10285 | #if ENABLE_FEATURE_TAB_COMPLETION | 10285 | #if ENABLE_FEATURE_TAB_COMPLETION |
10286 | static const char * FAST_FUNC | 10286 | static const char * FAST_FUNC |
10287 | get_builtin_name(int i) | 10287 | ash_command_name(int i) |
10288 | { | 10288 | { |
10289 | return /*i >= 0 &&*/ i < ARRAY_SIZE(builtintab) ? builtintab[i].name + 1 : NULL; | 10289 | int n; |
10290 | |||
10291 | if (/*i >= 0 &&*/ i < ARRAY_SIZE(builtintab)) | ||
10292 | return builtintab[i].name + 1; | ||
10293 | i -= ARRAY_SIZE(builtintab); | ||
10294 | |||
10295 | for (n = 0; n < CMDTABLESIZE; n++) { | ||
10296 | struct tblentry *cmdp; | ||
10297 | for (cmdp = cmdtable[n]; cmdp; cmdp = cmdp->next) { | ||
10298 | if (cmdp->cmdtype == CMDFUNCTION && --i < 0) | ||
10299 | return cmdp->cmdname; | ||
10300 | } | ||
10301 | } | ||
10302 | |||
10303 | # if ENABLE_ASH_ALIAS | ||
10304 | for (n = 0; n < ATABSIZE; n++) { | ||
10305 | struct alias *ap; | ||
10306 | for (ap = atab[n]; ap; ap = ap->next) { | ||
10307 | if (--i < 0) | ||
10308 | return ap->name; | ||
10309 | } | ||
10310 | } | ||
10311 | #endif | ||
10312 | |||
10313 | return NULL; | ||
10290 | } | 10314 | } |
10291 | #endif | 10315 | #endif |
10292 | 10316 | ||