aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-04-13 11:54:33 +0100
committerRon Yorston <rmy@pobox.com>2023-04-13 11:54:33 +0100
commite9c2749f6a9406bf0f696e065e0f221f9e763c74 (patch)
tree961dd92e1cdc0210e283ee07e59fa54ed2ef8844
parenta26711a2d1464167be4ebc990fe21a3809a2da34 (diff)
downloadbusybox-w32-tab_completion2.tar.gz
busybox-w32-tab_completion2.tar.bz2
busybox-w32-tab_completion2.zip
ash,hush: tab completion of functions and aliasestab_completion2
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 - 98 +98 hush_command_name - 71 +71 ash_builtin_name 17 - -17 hush_builtin_name 38 - -38 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 0/0 up/down: 169/-55) Total: 114 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Avi Halachmi <avihpit@yahoo.com>
-rw-r--r--shell/ash.c30
-rw-r--r--shell/hush.c11
2 files changed, 35 insertions, 6 deletions
diff --git a/shell/ash.c b/shell/ash.c
index d4ee4c93e..055f5ff73 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
9735static const char *get_builtin_name(int i) FAST_FUNC; 9735static 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,31 @@ find_builtin(const char *name)
10284 10284
10285#if ENABLE_FEATURE_TAB_COMPLETION 10285#if ENABLE_FEATURE_TAB_COMPLETION
10286static const char * FAST_FUNC 10286static const char * FAST_FUNC
10287get_builtin_name(int i) 10287ash_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 for (struct tblentry *cmdp = cmdtable[n]; cmdp; cmdp = cmdp->next) {
10297 if (cmdp->cmdtype == CMDFUNCTION && i-- <= 0)
10298 return cmdp->cmdname;
10299 }
10300 }
10301
10302# if ENABLE_ASH_ALIAS
10303 for (n = 0; n < ATABSIZE; n++) {
10304 for(struct alias *ap = atab[n]; ap; ap = ap->next) {
10305 if (i-- <= 0)
10306 return ap->name;
10307 }
10308 }
10309#endif
10310
10311 return NULL;
10290} 10312}
10291#endif 10313#endif
10292 10314
diff --git a/shell/hush.c b/shell/hush.c
index a938cc790..254e0b0ef 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -8220,7 +8220,7 @@ static const struct built_in_command *find_builtin(const char *name)
8220} 8220}
8221 8221
8222#if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION 8222#if ENABLE_HUSH_JOB && ENABLE_FEATURE_TAB_COMPLETION
8223static const char * FAST_FUNC get_builtin_name(int i) 8223static const char * FAST_FUNC hush_command_name(int i)
8224{ 8224{
8225 if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) { 8225 if (/*i >= 0 && */ i < ARRAY_SIZE(bltins1)) {
8226 return bltins1[i].b_cmd; 8226 return bltins1[i].b_cmd;
@@ -8229,6 +8229,13 @@ static const char * FAST_FUNC get_builtin_name(int i)
8229 if (i < ARRAY_SIZE(bltins2)) { 8229 if (i < ARRAY_SIZE(bltins2)) {
8230 return bltins2[i].b_cmd; 8230 return bltins2[i].b_cmd;
8231 } 8231 }
8232# if ENABLE_HUSH_FUNCTIONS
8233 i -= ARRAY_SIZE(bltins2);
8234 for (struct function *funcp = G.top_func; funcp; funcp = funcp->next) {
8235 if (i-- <= 0)
8236 return funcp->name;
8237 }
8238# endif
8232 return NULL; 8239 return NULL;
8233} 8240}
8234#endif 8241#endif
@@ -10716,7 +10723,7 @@ int hush_main(int argc, char **argv)
10716# if ENABLE_FEATURE_EDITING 10723# if ENABLE_FEATURE_EDITING
10717 G.line_input_state = new_line_input_t(FOR_SHELL); 10724 G.line_input_state = new_line_input_t(FOR_SHELL);
10718# if ENABLE_FEATURE_TAB_COMPLETION 10725# if ENABLE_FEATURE_TAB_COMPLETION
10719 G.line_input_state->get_exe_name = get_builtin_name; 10726 G.line_input_state->get_exe_name = hush_command_name;
10720# endif 10727# endif
10721# if EDITING_HAS_sh_get_var 10728# if EDITING_HAS_sh_get_var
10722 G.line_input_state->sh_get_var = get_local_var_value; 10729 G.line_input_state->sh_get_var = get_local_var_value;